diff --git a/src/libmdb/data.c b/src/libmdb/data.c index bd38445..738d6df 100644 --- a/src/libmdb/data.c +++ b/src/libmdb/data.c @@ -494,10 +494,10 @@ void mdb_data_dump(MdbTableDef *table) { unsigned int i; int ret; - char *bound_values[MDB_MAX_COLS]; + char **bound_values = calloc(table->num_cols, sizeof(char *)); for (i=0;inum_cols;i++) { - bound_values[i] = (char *) g_malloc(256); + bound_values[i] = (char *) g_malloc(MDB_BIND_SIZE); ret = mdb_bind_column(table, i+1, bound_values[i], NULL); if (ret == -1) { fprintf(stderr, "error binding column %d\n", i+1); @@ -516,6 +516,7 @@ void mdb_data_dump(MdbTableDef *table) for (i=0;inum_cols;i++) { g_free(bound_values[i]); } + free(bound_values); } int mdb_is_fixed_col(MdbColumn *col) diff --git a/src/util/mdb-import.c b/src/util/mdb-import.c index 65a1ddb..15993be 100644 --- a/src/util/mdb-import.c +++ b/src/util/mdb-import.c @@ -151,7 +151,7 @@ main(int argc, char **argv) int i, row; MdbHandle *mdb; MdbTableDef *table; - MdbField fields[256]; + MdbField *fields; char line[MAX_ROW_SIZE]; int num_fields; /* doesn't handle tables > 256 columns. Can that happen? */ @@ -207,13 +207,14 @@ main(int argc, char **argv) exit(1); } for (i=0;inum_cols, sizeof(MdbField)); + while (fgets(line, sizeof(line), in)) { num_fields = prep_row(table, line, fields, delimiter); if (!num_fields) { fprintf(stderr, "Aborting import at row %d\n", row); @@ -231,6 +232,7 @@ main(int argc, char **argv) g_option_context_free(opt_context); g_free(delimiter); + free(fields); return 0; } diff --git a/src/util/mdb-prop.c b/src/util/mdb-prop.c index 9e9dc24..9acb4ae 100644 --- a/src/util/mdb-prop.c +++ b/src/util/mdb-prop.c @@ -25,7 +25,7 @@ main(int argc, char **argv) { MdbHandle *mdb; MdbTableDef *table; - gchar name[256]; + char *name; gchar *propColName; void *buf; int col_num; @@ -54,10 +54,12 @@ main(int argc, char **argv) mdb_read_columns(table); mdb_rewind_table(table); + name = g_malloc(mdb->bind_size); + buf = g_malloc(mdb->bind_size); mdb_bind_column_by_name(table, "Name", name, NULL); - buf = g_malloc(MDB_BIND_SIZE); col_num = mdb_bind_column_by_name(table, propColName, buf, NULL); if (col_num < 1) { + g_free(name); g_free(buf); mdb_free_tabledef(table); mdb_close(mdb); @@ -83,6 +85,7 @@ main(int argc, char **argv) free(kkd); } + g_free(name); g_free(buf); mdb_free_tabledef(table); mdb_close(mdb); diff --git a/src/util/mdb-queries.c b/src/util/mdb-queries.c index ab8d7bc..69d34fe 100644 --- a/src/util/mdb-queries.c +++ b/src/util/mdb-queries.c @@ -51,21 +51,21 @@ int main (int argc, char **argv) { char *query_id; size_t bind_size = QUERY_BIND_SIZE; - // variables for the msysqueries table. hopefully 256 is big enough - char *attribute = (char *) malloc(bind_size); - char *expression = (char *) malloc(bind_size); - char *flag = (char *) malloc(bind_size); - char *name1 = (char *) malloc(bind_size); - char *name2 = (char *) malloc(bind_size); - char *objectid = (char *) malloc(bind_size); - char *order = (char *) malloc(bind_size); + // variables for the msysqueries table + char *attribute = malloc(bind_size); + char *expression = malloc(bind_size); + char *flag = malloc(bind_size); + char *name1 = malloc(bind_size); + char *name2 = malloc(bind_size); + char *objectid = malloc(bind_size); + char *order = malloc(bind_size); //variables for the generation of sql - char *sql_tables = (char *) malloc(bind_size); - char *sql_predicate = (char *) malloc(bind_size); - char *sql_columns = (char *) malloc(bind_size); - char *sql_where = (char *) malloc(bind_size); - char *sql_sorting = (char *) malloc(bind_size); + char *sql_tables = malloc(bind_size); + char *sql_predicate = malloc(bind_size); + char *sql_columns = malloc(bind_size); + char *sql_where = malloc(bind_size); + char *sql_sorting = malloc(bind_size); int flagint; /* see getopt(3) for more information on getopt and this will become clear */ @@ -216,6 +216,7 @@ int main (int argc, char **argv) { mdb_free_tabledef(table); } + free(query_id); } else { fprintf(stderr,"Couldn't locate the specified query: %s\n",argv[optind+1]); } @@ -269,8 +270,8 @@ char * mdb_get_query_id(MdbHandle *mdb, char *query) { unsigned int i; MdbCatalogEntry *entry = NULL; MdbTableDef *table = NULL; - static char id[256]; - char name[256]; + char *id = malloc(mdb->bind_size); + char *name = malloc(mdb->bind_size); /* loop over each entry in the catalog */ for (i=0; i < mdb->num_catalog; i++) { @@ -298,6 +299,8 @@ char * mdb_get_query_id(MdbHandle *mdb, char *query) { } mdb_free_tabledef(table); } + + free(name); return id; }