Code cleanup

Enforce consistency g_malloc - g_free and malloc - free
Move var declarations on top of functions
This commit is contained in:
Jimmytaker
2012-12-31 20:40:12 +01:00
committed by Nirgal Vourgère
parent 5eeb5c5050
commit c9f602480b
3 changed files with 22 additions and 18 deletions

View File

@@ -515,7 +515,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
fprintf (outfile, " UNIQUE"); fprintf (outfile, " UNIQUE");
fprintf(outfile, " INDEX %s ON %s (", quoted_name, quoted_table_name); fprintf(outfile, " INDEX %s ON %s (", quoted_name, quoted_table_name);
} }
free(quoted_name); g_free(quoted_name);
free(index_name); free(index_name);
for (j=0;j<idx->num_keys;j++) { for (j=0;j<idx->num_keys;j++) {
@@ -528,7 +528,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
/* no DESC for primary keys */ /* no DESC for primary keys */
fprintf(outfile, " DESC"); fprintf(outfile, " DESC");
free(quoted_name); g_free(quoted_name);
} }
fprintf (outfile, ");\n"); fprintf (outfile, ");\n");
@@ -635,7 +635,7 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
grbit = atoi(bound[4]); grbit = atoi(bound[4]);
constraint_name = g_strconcat(bound[1], "_", bound[0], "_fk", NULL); constraint_name = g_strconcat(bound[1], "_", bound[0], "_fk", NULL);
quoted_constraint_name = mdb->default_backend->quote_schema_name(dbnamespace, constraint_name); quoted_constraint_name = mdb->default_backend->quote_schema_name(dbnamespace, constraint_name);
free(constraint_name); g_free(constraint_name);
if (grbit & 0x00000002) { if (grbit & 0x00000002) {
text = g_strconcat( text = g_strconcat(
@@ -660,11 +660,11 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
break; break;
} }
} }
free(quoted_table_1); g_free(quoted_table_1);
free(quoted_column_1); g_free(quoted_column_1);
free(quoted_table_2); g_free(quoted_table_2);
free(quoted_column_2); g_free(quoted_column_2);
free(quoted_constraint_name); g_free(quoted_constraint_name);
return (char *)text; return (char *)text;
} }
@@ -703,7 +703,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name); quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
fprintf (outfile, "\t%s\t\t\t%s", quoted_name, fprintf (outfile, "\t%s\t\t\t%s", quoted_name,
mdb_get_colbacktype_string (col)); mdb_get_colbacktype_string (col));
free(quoted_name); g_free(quoted_name);
if (mdb_colbacktype_takes_length(col)) { if (mdb_colbacktype_takes_length(col)) {
@@ -736,7 +736,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
if (defval[0]=='"' && defval[def_len-1]=='"') { if (defval[0]=='"' && defval[def_len-1]=='"') {
/* this is a string */ /* this is a string */
gchar *output_default = malloc(def_len-1); gchar *output_default = malloc(def_len-1);
gchar *output_default_escaped = malloc(def_len-1); gchar *output_default_escaped;
memcpy(output_default, defval+1, def_len-2); memcpy(output_default, defval+1, def_len-2);
output_default[def_len-2] = 0; output_default[def_len-2] = 0;
output_default_escaped = quote_with_squotes(output_default); output_default_escaped = quote_with_squotes(output_default);
@@ -794,11 +794,11 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
fprintf(outfile, fprintf(outfile,
mdb->default_backend->column_comment_statement, mdb->default_backend->column_comment_statement,
quoted_table_name, quoted_name, comment); quoted_table_name, quoted_name, comment);
free(comment); g_free(comment);
} }
} }
free(quoted_name); g_free(quoted_name);
} }
/* Add the constraints on table */ /* Add the constraints on table */
@@ -809,7 +809,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
fprintf(outfile, fprintf(outfile,
mdb->default_backend->table_comment_statement, mdb->default_backend->table_comment_statement,
quoted_table_name, comment); quoted_table_name, comment);
free(comment); g_free(comment);
} }
} }
fputc('\n', outfile); fputc('\n', outfile);
@@ -819,7 +819,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
// prints all the indexes of that table // prints all the indexes of that table
mdb_print_indexes(outfile, table, dbnamespace); mdb_print_indexes(outfile, table, dbnamespace);
free(quoted_table_name); g_free(quoted_table_name);
mdb_free_tabledef (table); mdb_free_tabledef (table);
} }
@@ -831,6 +831,7 @@ mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace
unsigned int i; unsigned int i;
char *the_relation; char *the_relation;
MdbCatalogEntry *entry; MdbCatalogEntry *entry;
const char *charset;
/* clear unsupported options */ /* clear unsupported options */
export_options &= mdb->default_backend->capabilities; export_options &= mdb->default_backend->capabilities;
@@ -846,7 +847,7 @@ mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace
"-- ----------------------------------------------------------\n\n", "-- ----------------------------------------------------------\n\n",
outfile); outfile);
const char *charset = mdb_target_charset(mdb); charset = mdb_target_charset(mdb);
if (charset) { if (charset) {
fprintf(outfile, mdb->default_backend->charset_statement, charset); fprintf(outfile, mdb->default_backend->charset_statement, charset);
fputc('\n', outfile); fputc('\n', outfile);

View File

@@ -25,9 +25,9 @@ mdb_read_props_list(MdbHandle *mdb, gchar *kkd, int len)
int pos = 0; int pos = 0;
gchar *name; gchar *name;
GPtrArray *names = NULL; GPtrArray *names = NULL;
int i=0;
names = g_ptr_array_new(); names = g_ptr_array_new();
int i=0;
#if MDB_DEBUG #if MDB_DEBUG
mdb_buffer_dump(kkd, 0, len); mdb_buffer_dump(kkd, 0, len);
#endif #endif
@@ -157,18 +157,20 @@ mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
size_t pos; size_t pos;
GPtrArray *names = NULL; GPtrArray *names = NULL;
MdbProperties *props; MdbProperties *props;
GArray *result;
#if MDB_DEBUG #if MDB_DEBUG
mdb_buffer_dump(buffer, 0, len); mdb_buffer_dump(buffer, 0, len);
#endif #endif
mdb_debug(MDB_DEBUG_PROPS,"starting prop parsing of type %s", buffer); mdb_debug(MDB_DEBUG_PROPS,"starting prop parsing of type %s", buffer);
if (strcmp("KKD", buffer) && strcmp("MR2", buffer)) { if (strcmp("KKD", buffer) && strcmp("MR2", buffer)) {
fprintf(stderr, "Unrecognized format.\n"); fprintf(stderr, "Unrecognized format.\n");
mdb_buffer_dump(buffer, 0, len); mdb_buffer_dump(buffer, 0, len);
return NULL; return NULL;
} }
GArray *result = g_array_new(0, 0, sizeof(MdbProperties*)); result = g_array_new(0, 0, sizeof(MdbProperties*));
pos = 4; pos = 4;
while (pos < len) { while (pos < len) {

View File

@@ -215,6 +215,7 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
unsigned int i, j; unsigned int i, j;
int cur_pos; int cur_pos;
size_t name_sz; size_t name_sz;
GArray *allprops;
table->columns = g_ptr_array_new(); table->columns = g_ptr_array_new();
@@ -302,7 +303,7 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
/* Sort the columns by col_num */ /* Sort the columns by col_num */
g_ptr_array_sort(table->columns, (GCompareFunc)mdb_col_comparer); g_ptr_array_sort(table->columns, (GCompareFunc)mdb_col_comparer);
GArray *allprops = table->entry->props; allprops = table->entry->props;
if (allprops) if (allprops)
for (i=0;i<table->num_cols;i++) { for (i=0;i<table->num_cols;i++) {
pcol = g_ptr_array_index(table->columns, i); pcol = g_ptr_array_index(table->columns, i);