Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Enforce consistency g_malloc - g_free and malloc - free
Move var declarations on top of functions
  • Loading branch information
jimmytaker authored and Nirgal Vourgère committed Jan 13, 2013
1 parent 5eeb5c5 commit c9f6024
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
31 changes: 16 additions & 15 deletions src/libmdb/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
fprintf (outfile, " UNIQUE");
fprintf(outfile, " INDEX %s ON %s (", quoted_name, quoted_table_name);
}
free(quoted_name);
g_free(quoted_name);
free(index_name);

for (j=0;j<idx->num_keys;j++) {
Expand All @@ -528,7 +528,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
/* no DESC for primary keys */
fprintf(outfile, " DESC");

free(quoted_name);
g_free(quoted_name);

}
fprintf (outfile, ");\n");
Expand Down Expand Up @@ -635,7 +635,7 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
grbit = atoi(bound[4]);
constraint_name = g_strconcat(bound[1], "_", bound[0], "_fk", NULL);
quoted_constraint_name = mdb->default_backend->quote_schema_name(dbnamespace, constraint_name);
free(constraint_name);
g_free(constraint_name);

if (grbit & 0x00000002) {
text = g_strconcat(
Expand All @@ -660,11 +660,11 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
break;
}
}
free(quoted_table_1);
free(quoted_column_1);
free(quoted_table_2);
free(quoted_column_2);
free(quoted_constraint_name);
g_free(quoted_table_1);
g_free(quoted_column_1);
g_free(quoted_table_2);
g_free(quoted_column_2);
g_free(quoted_constraint_name);

return (char *)text;
}
Expand Down Expand Up @@ -703,7 +703,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
fprintf (outfile, "\t%s\t\t\t%s", quoted_name,
mdb_get_colbacktype_string (col));
free(quoted_name);
g_free(quoted_name);

if (mdb_colbacktype_takes_length(col)) {

Expand Down Expand Up @@ -736,7 +736,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
if (defval[0]=='"' && defval[def_len-1]=='"') {
/* this is a string */
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);
output_default[def_len-2] = 0;
output_default_escaped = quote_with_squotes(output_default);
Expand Down Expand Up @@ -794,11 +794,11 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
fprintf(outfile,
mdb->default_backend->column_comment_statement,
quoted_table_name, quoted_name, comment);
free(comment);
g_free(comment);
}
}

free(quoted_name);
g_free(quoted_name);
}

/* Add the constraints on table */
Expand All @@ -809,7 +809,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
fprintf(outfile,
mdb->default_backend->table_comment_statement,
quoted_table_name, comment);
free(comment);
g_free(comment);
}
}
fputc('\n', outfile);
Expand All @@ -819,7 +819,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
// prints all the indexes of that table
mdb_print_indexes(outfile, table, dbnamespace);

free(quoted_table_name);
g_free(quoted_table_name);

mdb_free_tabledef (table);
}
Expand All @@ -831,6 +831,7 @@ mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace
unsigned int i;
char *the_relation;
MdbCatalogEntry *entry;
const char *charset;

/* clear unsupported options */
export_options &= mdb->default_backend->capabilities;
Expand All @@ -846,7 +847,7 @@ mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace
"-- ----------------------------------------------------------\n\n",
outfile);

const char *charset = mdb_target_charset(mdb);
charset = mdb_target_charset(mdb);
if (charset) {
fprintf(outfile, mdb->default_backend->charset_statement, charset);
fputc('\n', outfile);
Expand Down
6 changes: 4 additions & 2 deletions src/libmdb/props.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ mdb_read_props_list(MdbHandle *mdb, gchar *kkd, int len)
int pos = 0;
gchar *name;
GPtrArray *names = NULL;
int i=0;

names = g_ptr_array_new();
int i=0;
#if MDB_DEBUG
mdb_buffer_dump(kkd, 0, len);
#endif
Expand Down Expand Up @@ -157,18 +157,20 @@ mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
size_t pos;
GPtrArray *names = NULL;
MdbProperties *props;
GArray *result;

#if MDB_DEBUG
mdb_buffer_dump(buffer, 0, len);
#endif
mdb_debug(MDB_DEBUG_PROPS,"starting prop parsing of type %s", buffer);

if (strcmp("KKD", buffer) && strcmp("MR2", buffer)) {
fprintf(stderr, "Unrecognized format.\n");
mdb_buffer_dump(buffer, 0, len);
return NULL;
}

GArray *result = g_array_new(0, 0, sizeof(MdbProperties*));
result = g_array_new(0, 0, sizeof(MdbProperties*));

pos = 4;
while (pos < len) {
Expand Down
3 changes: 2 additions & 1 deletion src/libmdb/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
unsigned int i, j;
int cur_pos;
size_t name_sz;
GArray *allprops;

table->columns = g_ptr_array_new();

Expand Down Expand Up @@ -302,7 +303,7 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
/* Sort the columns by col_num */
g_ptr_array_sort(table->columns, (GCompareFunc)mdb_col_comparer);

GArray *allprops = table->entry->props;
allprops = table->entry->props;
if (allprops)
for (i=0;i<table->num_cols;i++) {
pcol = g_ptr_array_index(table->columns, i);
Expand Down

0 comments on commit c9f6024

Please sign in to comment.