diff options
author | ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2008-12-15 00:18:11 (EST) |
---|---|---|
committer | ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2008-12-15 00:18:11 (EST) |
commit | 90299e3df5c5d5eb4ae2189b11e44ec83995ca62 (patch) | |
tree | a405f8b82e3b9514d9397698bba73742dfc4ede6 /libopkg/hash_table.c | |
parent | ddd373d69aac313269e6465a83c633d9a1815643 (diff) |
opkg: (leak fixing, day 1) lots and lots of memory leaks fixed
git-svn-id: http://opkg.googlecode.com/svn/trunk@114 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg/hash_table.c')
-rw-r--r-- | libopkg/hash_table.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/libopkg/hash_table.c b/libopkg/hash_table.c index 41877c2..c0c0530 100644 --- a/libopkg/hash_table.c +++ b/libopkg/hash_table.c @@ -78,7 +78,26 @@ int hash_table_init(const char *name, hash_table_t *hash, int len) void hash_table_deinit(hash_table_t *hash) { - free(hash->entries); + int i; + if (!hash) + return; + + /* free the reminaing entries */ + for (i = 0; i < hash->n_entries; i++) { + hash_entry_t *hash_entry = (hash->entries + i); + /* skip the first entry as this is part of the array */ + hash_entry = hash_entry->next; + while (hash_entry) + { + hash_entry_t *old = hash_entry; + hash_entry = hash_entry->next; + free (old->key); + free (old); + } + } + + free (hash->entries); + hash->entries = NULL; hash->n_entries = 0; } |