diff options
author | Mike Engber <engber@src.gnome.org> | 2000-10-24 23:03:36 +0000 |
---|---|---|
committer | Mike Engber <engber@src.gnome.org> | 2000-10-24 23:03:36 +0000 |
commit | 4750fa1d35e71a1ad6bda94999af1326db37a9dc (patch) | |
tree | 975d66fee1c24f439c4abfc6cc89f43aee702e08 /libnautilus-extensions | |
parent | 56eb46127c7c9fd2ac3edee0ccc8e215ab7940bb (diff) | |
download | nautilus-4750fa1d35e71a1ad6bda94999af1326db37a9dc.tar.gz |
These two fns now properly handle key == value (won't double free)
* libnautilus-extensions/nautilus-glib-extensions.c:
(nautilus_g_hash_table_remove_deep_custom),
(nautilus_g_hash_table_destroy_deep_helper):
These two fns now properly handle key == value (won't double free)
Diffstat (limited to 'libnautilus-extensions')
-rw-r--r-- | libnautilus-extensions/nautilus-glib-extensions.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libnautilus-extensions/nautilus-glib-extensions.c b/libnautilus-extensions/nautilus-glib-extensions.c index 36c01702d..2c499ddf4 100644 --- a/libnautilus-extensions/nautilus-glib-extensions.c +++ b/libnautilus-extensions/nautilus-glib-extensions.c @@ -890,10 +890,11 @@ nautilus_g_hash_table_remove_deep_custom (GHashTable *hash_table, gconstpointer */ if (g_hash_table_lookup_extended (hash_table, key, &key_in_table, &value)) { g_hash_table_remove (hash_table, key); - if (key_free_func) { + if (key_free_func != NULL) { key_free_func (key_in_table, key_free_data); } - if (value_free_func) { + /* handle key == value, don't double free */ + if (value_free_func != NULL && value != key_in_table) { value_free_func (value, value_free_data); } return TRUE; @@ -921,11 +922,12 @@ nautilus_g_hash_table_destroy_deep_helper (gpointer key, gpointer value, gpointe HashTableFreeFuncs *free_funcs; free_funcs = (HashTableFreeFuncs *) data; - if (free_funcs->key_free_func) { + if (free_funcs->key_free_func != NULL) { free_funcs->key_free_func (key, free_funcs->key_free_data); } - if (free_funcs->value_free_func) { - free_funcs->value_free_func (data, free_funcs->value_free_data); + /* handle key == value, don't double free */ + if (free_funcs->value_free_func != NULL && value != key) { + free_funcs->value_free_func (value, free_funcs->value_free_data); } return TRUE; } |