Changed the definition of gssize and fixed some memory leaks following code review.

This commit is contained in:
Jose Hernandez
2021-08-01 17:49:21 +01:00
parent afc6f4888b
commit f7b13bd4a7
4 changed files with 19 additions and 18 deletions

View File

@@ -39,7 +39,7 @@ typedef const void * gconstpointer;
typedef uint8_t guint8; typedef uint8_t guint8;
typedef guint32 GQuark; typedef guint32 GQuark;
typedef guint32 gunichar; typedef guint32 gunichar;
typedef signed int gssize; typedef signed long gssize;
typedef guint (*GHashFunc)(gconstpointer); typedef guint (*GHashFunc)(gconstpointer);
typedef int (*GCompareFunc)(gconstpointer, gconstpointer); typedef int (*GCompareFunc)(gconstpointer, gconstpointer);

View File

@@ -575,6 +575,7 @@ void mdb_register_backend(MdbHandle *mdb, char *backend_name, guint32 capabiliti
int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name); int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name);
int mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace, guint32 export_options); int mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace, guint32 export_options);
void mdb_print_col(FILE *outfile, gchar *col_val, int quote_text, int col_type, int bin_len, char *quote_char, char *escape_char, int flags); void mdb_print_col(FILE *outfile, gchar *col_val, int quote_text, int col_type, int bin_len, char *quote_char, char *escape_char, int flags);
gchar *mdb_normalise_and_replace(MdbHandle *mdb, gchar **str);
/* sargs.c */ /* sargs.c */
int mdb_test_sargs(MdbTableDef *table, MdbField *fields, int num_fields); int mdb_test_sargs(MdbTableDef *table, MdbField *fields, int num_fields);

View File

@@ -156,11 +156,11 @@ enum {
static void mdb_drop_backend(gpointer key, gpointer value, gpointer data); static void mdb_drop_backend(gpointer key, gpointer value, gpointer data);
gchar *passthrough_unchanged(const gchar *str) { static gchar *passthrough_unchanged(const gchar *str) {
return (gchar *)str; return (gchar *)str;
} }
gchar *to_lower_case(const gchar *str) { static gchar *to_lower_case(const gchar *str) {
return g_utf8_strdown(str, -1); return g_utf8_strdown(str, -1);
} }
@@ -174,7 +174,7 @@ gchar *to_lower_case(const gchar *str) {
* @param str string to normalise * @param str string to normalise
* @return a pointer to the normalised version of the input string * @return a pointer to the normalised version of the input string
*/ */
gchar *normalise_and_replace(MdbHandle *mdb, gchar **str) { gchar *mdb_normalise_and_replace(MdbHandle *mdb, gchar **str) {
gchar *normalised_str = mdb->default_backend->normalise_case(*str); gchar *normalised_str = mdb->default_backend->normalise_case(*str);
if (normalised_str != *str) { if (normalised_str != *str) {
/* Free and replace the old string only and only if a new string was created at a different memory location /* Free and replace the old string only and only if a new string was created at a different memory location
@@ -609,7 +609,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
quoted_name = mdb->default_backend->quote_schema_name(dbnamespace, index_name); quoted_name = mdb->default_backend->quote_schema_name(dbnamespace, index_name);
} }
quoted_name = normalise_and_replace(mdb, &quoted_name); quoted_name = mdb_normalise_and_replace(mdb, &quoted_name);
if (idx->index_type==1) { if (idx->index_type==1) {
switch (backend) { switch (backend) {
@@ -646,7 +646,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
fprintf(outfile, ", "); fprintf(outfile, ", ");
col=g_ptr_array_index(table->columns,idx->key_col_num[j]-1); col=g_ptr_array_index(table->columns,idx->key_col_num[j]-1);
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name); quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
quoted_name = normalise_and_replace(mdb, &quoted_name); quoted_name = mdb_normalise_and_replace(mdb, &quoted_name);
fprintf (outfile, "%s", quoted_name); fprintf (outfile, "%s", quoted_name);
if (idx->index_type!=1 && idx->key_col_order[j]) if (idx->index_type!=1 && idx->key_col_order[j])
/* no DESC for primary keys */ /* no DESC for primary keys */
@@ -754,11 +754,11 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
* be namespaced. * be namespaced.
*/ */
quoted_constraint_name = mdb->default_backend->quote_schema_name(NULL, constraint_name); quoted_constraint_name = mdb->default_backend->quote_schema_name(NULL, constraint_name);
quoted_constraint_name = normalise_and_replace(mdb, &quoted_constraint_name); quoted_constraint_name = mdb_normalise_and_replace(mdb, &quoted_constraint_name);
quoted_column_1 = mdb->default_backend->quote_schema_name(NULL, bound[0]); quoted_column_1 = mdb->default_backend->quote_schema_name(NULL, bound[0]);
quoted_column_1 = normalise_and_replace(mdb, &quoted_column_1); quoted_column_1 = mdb_normalise_and_replace(mdb, &quoted_column_1);
quoted_column_2 = mdb->default_backend->quote_schema_name(NULL, bound[2]); quoted_column_2 = mdb->default_backend->quote_schema_name(NULL, bound[2]);
quoted_column_2 = normalise_and_replace(mdb, &quoted_column_2); quoted_column_2 = mdb_normalise_and_replace(mdb, &quoted_column_2);
break; break;
default: default:
@@ -841,7 +841,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
const char *prop_value; const char *prop_value;
quoted_table_name = mdb->default_backend->quote_schema_name(dbnamespace, entry->object_name); quoted_table_name = mdb->default_backend->quote_schema_name(dbnamespace, entry->object_name);
quoted_table_name = normalise_and_replace(mdb, &quoted_table_name); quoted_table_name = mdb_normalise_and_replace(mdb, &quoted_table_name);
/* drop the table if it exists */ /* drop the table if it exists */
if (export_options & MDB_SHEXP_DROPTABLE) if (export_options & MDB_SHEXP_DROPTABLE)
@@ -861,7 +861,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
col = g_ptr_array_index (table->columns, i); col = g_ptr_array_index (table->columns, i);
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name); quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
quoted_name = normalise_and_replace(mdb, &quoted_name); quoted_name = mdb_normalise_and_replace(mdb, &quoted_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));
g_free(quoted_name); g_free(quoted_name);
@@ -964,7 +964,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
continue; continue;
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name); quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
quoted_name = normalise_and_replace(mdb, &quoted_name); quoted_name = mdb_normalise_and_replace(mdb, &quoted_name);
if (export_options & MDB_SHEXP_CST_NOTEMPTY) { if (export_options & MDB_SHEXP_CST_NOTEMPTY) {
prop_value = mdb_col_get_prop(col, "AllowZeroLength"); prop_value = mdb_col_get_prop(col, "AllowZeroLength");

View File

@@ -226,14 +226,14 @@ main(int argc, char **argv)
counter = 0; // reset to 0, prevent overflow on extremely large data sets. counter = 0; // reset to 0, prevent overflow on extremely large data sets.
char *quoted_name; char *quoted_name;
quoted_name = mdb->default_backend->quote_schema_name(namespace, table_name); quoted_name = mdb->default_backend->quote_schema_name(namespace, table_name);
quoted_name = mdb->default_backend->normalise_case(quoted_name); quoted_name = mdb_normalise_and_replace(mdb, &quoted_name);
fprintf(outfile, "INSERT INTO %s (", quoted_name); fprintf(outfile, "INSERT INTO %s (", quoted_name);
free(quoted_name); free(quoted_name);
for (i = 0; i < table->num_cols; i++) { for (i = 0; i < table->num_cols; i++) {
if (i > 0) fputs(", ", outfile); if (i > 0) fputs(", ", outfile);
col = g_ptr_array_index(table->columns, i); col = g_ptr_array_index(table->columns, i);
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name); quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
quoted_name = mdb->default_backend->normalise_case(quoted_name); quoted_name = mdb_normalise_and_replace(mdb, &quoted_name);
fputs(quoted_name, outfile); fputs(quoted_name, outfile);
free(quoted_name); free(quoted_name);
} }
@@ -286,14 +286,14 @@ main(int argc, char **argv)
if (insert_dialect) { if (insert_dialect) {
char *quoted_name; char *quoted_name;
quoted_name = mdb->default_backend->quote_schema_name(namespace, table_name); quoted_name = mdb->default_backend->quote_schema_name(namespace, table_name);
quoted_name = mdb->default_backend->normalise_case(quoted_name); quoted_name = mdb_normalise_and_replace(mdb, &quoted_name);
fprintf(outfile, "INSERT INTO %s (", quoted_name); fprintf(outfile, "INSERT INTO %s (", quoted_name);
free(quoted_name); free(quoted_name);
for (i = 0; i < table->num_cols; i++) { for (i = 0; i < table->num_cols; i++) {
if (i > 0) fputs(", ", outfile); if (i > 0) fputs(", ", outfile);
col = g_ptr_array_index(table->columns, i); col = g_ptr_array_index(table->columns, i);
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name); quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
quoted_name = mdb->default_backend->normalise_case(quoted_name); quoted_name = mdb_normalise_and_replace(mdb, &quoted_name);
fputs(quoted_name, outfile); fputs(quoted_name, outfile);
free(quoted_name); free(quoted_name);
} }