aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/ChangeLog5
-rw-r--r--e-util/e-pilot-map.c32
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);
}
-
-
-
-
-
-
-
-