From fd6e52f9bd8fc610f589d6d3c8e6930cbc4d969b Mon Sep 17 00:00:00 2001 From: William Rogers Date: Fri, 14 Jun 2013 12:36:20 -0500 Subject: [PATCH] Fixed MDBProps memory leaks --- src/libmdb/catalog.c | 16 +++++++++++++--- src/libmdb/props.c | 13 ++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/libmdb/catalog.c b/src/libmdb/catalog.c index 07c0c9c..da09ec4 100644 --- a/src/libmdb/catalog.c +++ b/src/libmdb/catalog.c @@ -48,11 +48,21 @@ static char *type_name[] = {"Form", void mdb_free_catalog(MdbHandle *mdb) { - unsigned int i; + unsigned int i, j; + MdbCatalogEntry *entry; if ((!mdb) || (!mdb->catalog)) return; - for (i=0; icatalog->len; i++) - g_free (g_ptr_array_index(mdb->catalog, i)); + for (i=0; icatalog->len; i++) { + entry = (MdbCatalogEntry *)g_ptr_array_index(mdb->catalog, i); + if (entry) { + if (entry->props) { + for (j=0; jprops->len; j++) + mdb_free_props(g_array_index(entry->props, MdbProperties*, j)); + g_array_free(entry->props, TRUE); + } + g_free(entry); + } + } g_ptr_array_free(mdb->catalog, TRUE); mdb->catalog = NULL; } diff --git a/src/libmdb/props.c b/src/libmdb/props.c index 57746c7..d1a3841 100644 --- a/src/libmdb/props.c +++ b/src/libmdb/props.c @@ -50,12 +50,23 @@ mdb_read_props_list(MdbHandle *mdb, gchar *kkd, int len) } return names; } +static gboolean +free_hash_entry(gpointer key, gpointer value, gpointer user_data) +{ + g_free(key); + g_free(value); + return TRUE; +} void mdb_free_props(MdbProperties *props) { if (!props) return; if (props->name) g_free(props->name); + if (props->hash) { + g_hash_table_foreach(props->hash, (GHFunc)free_hash_entry, 0); + g_hash_table_destroy(props->hash); + } g_free(props); } @@ -148,7 +159,7 @@ mdb_dump_props(MdbProperties *props, FILE *outfile, int show_name) { /* * That function takes a raw KKD/MR2 binary buffer, * typically read from LvProp in table MSysbjects - * and returns a GPtrArray of MdbProps* + * and returns a GArray of MdbProps* */ GArray* mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {