diff options
author | JP Rosevear <jpr@ximian.com> | 2001-10-26 23:29:49 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2001-10-26 23:29:49 +0800 |
commit | f113b35e501cbeb814e2c050c9df2280a33c9937 (patch) | |
tree | 4e5cd309fbe8fcbe08a3046947b4735b1c179c04 | |
parent | 67b2ea50b1ff25e68f33de33df61275f06bceece (diff) | |
download | gsoc2013-evolution-f113b35e501cbeb814e2c050c9df2280a33c9937.tar.gz gsoc2013-evolution-f113b35e501cbeb814e2c050c9df2280a33c9937.tar.zst gsoc2013-evolution-f113b35e501cbeb814e2c050c9df2280a33c9937.zip |
free up old memory first (e_pilot_map_destroy): free allocated memory when
2001-10-26 JP Rosevear <jpr@ximian.com>
* 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
-rw-r--r-- | e-util/ChangeLog | 5 | ||||
-rw-r--r-- | e-util/e-pilot-map.c | 32 |
2 files changed, 29 insertions, 8 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 18626d9060..ccfaac772e 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,8 @@ +2001-10-26 JP Rosevear <jpr@ximian.com> + + * e-pilot-map.c (e_pilot_map_insert): free up old memory first + (e_pilot_map_destroy): free allocated memory when destroying + 2001-10-22 JP Rosevear <jpr@ximian.com> * e-pilot-map.c (map_set_node_timet): plug leak 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); } - - - - - - - - |