From f113b35e501cbeb814e2c050c9df2280a33c9937 Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Fri, 26 Oct 2001 15:29:49 +0000 Subject: free up old memory first (e_pilot_map_destroy): free allocated memory when 2001-10-26 JP Rosevear * e-pilot-map.c (e_pilot_map_insert): free up old memory first (e_pilot_map_destroy): free allocated memory when destroying svn path=/trunk/; revision=14143 --- e-util/e-pilot-map.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'e-util/e-pilot-map.c') diff --git a/e-util/e-pilot-map.c b/e-util/e-pilot-map.c index fb978b08ec..4aa1c4388d 100644 --- a/e-util/e-pilot-map.c +++ b/e-util/e-pilot-map.c @@ -152,6 +152,7 @@ e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archi guint32 *new_pid = g_new (guint32, 1); EPilotMapPidNode *pnode = g_new0 (EPilotMapPidNode, 1); EPilotMapUidNode *unode = g_new0 (EPilotMapUidNode, 1); + gpointer key, value; *new_pid = pid; new_uid = g_strdup (uid); @@ -161,6 +162,17 @@ e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archi unode->pid = pid; unode->archived = archived; + + if (g_hash_table_lookup_extended (map->pid_map, new_pid, &key, &value)) { + g_hash_table_remove (map->pid_map, new_pid); + g_free (key); + g_free (value); + } + if (g_hash_table_lookup_extended (map->uid_map, new_uid, &key, &value)) { + g_hash_table_remove (map->uid_map, new_uid); + g_free (key); + g_free (value); + } g_hash_table_insert (map->pid_map, new_pid, pnode); g_hash_table_insert (map->uid_map, new_uid, unode); @@ -289,18 +301,22 @@ e_pilot_map_write (const char *filename, EPilotMap *map) return 0; } +static gboolean +foreach_remove (gpointer key, gpointer value, gpointer data) +{ + g_free (key); + g_free (value); + + return TRUE; +} + void e_pilot_map_destroy (EPilotMap *map) { + g_hash_table_foreach_remove (map->pid_map, foreach_remove, NULL); + g_hash_table_foreach_remove (map->uid_map, foreach_remove, NULL); + g_hash_table_destroy (map->pid_map); g_hash_table_destroy (map->uid_map); g_free (map); } - - - - - - - - -- cgit v1.2.3