[gnome-photos] tracker-change-monitor: Plug a memory leak



commit ee8c1a91a75e347b8dae0b12ad668fbcdcca5902
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Sep 17 17:48:24 2014 +0200

    tracker-change-monitor: Plug a memory leak
    
    Trying to avoid copying the TrackerChangeEvents led us to leaking them
    if the query to resolve their IDs failed. Let's not do that.
    
    Fixes: https://bugzilla.gnome.org/735746

 src/photos-tracker-change-event.c   |   16 ++++++++++++++++
 src/photos-tracker-change-event.h   |    2 ++
 src/photos-tracker-change-monitor.c |   11 ++++-------
 3 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/src/photos-tracker-change-event.c b/src/photos-tracker-change-event.c
index 8d36f2d..167d744 100644
--- a/src/photos-tracker-change-event.c
+++ b/src/photos-tracker-change-event.c
@@ -68,6 +68,22 @@ photos_tracker_change_event_new (gint32 urn_id, gint32 predicate_id, gboolean is
 }
 
 
+PhotosTrackerChangeEvent *
+photos_tracker_change_event_copy (PhotosTrackerChangeEvent *event)
+{
+  PhotosTrackerChangeEvent *self;
+
+  self = g_slice_new0 (PhotosTrackerChangeEvent);
+  self->type = event->type;
+  self->predicate = g_strdup (event->predicate);
+  self->urn = g_strdup (event->urn);
+  self->predicate_id = event->predicate_id;
+  self->urn_id = event->urn_id;
+
+  return self;
+}
+
+
 PhotosTrackerChangeEventType
 photos_tracker_change_event_get_type (PhotosTrackerChangeEvent *self)
 {
diff --git a/src/photos-tracker-change-event.h b/src/photos-tracker-change-event.h
index 2ac9bd3..9a38420 100644
--- a/src/photos-tracker-change-event.h
+++ b/src/photos-tracker-change-event.h
@@ -42,6 +42,8 @@ PhotosTrackerChangeEvent  *photos_tracker_change_event_new        (gint32 urn_id
                                                                    gint32 predicate_id,
                                                                    gboolean is_delete);
 
+PhotosTrackerChangeEvent  *photos_tracker_change_event_copy       (PhotosTrackerChangeEvent *event);
+
 void                       photos_tracker_change_event_free       (PhotosTrackerChangeEvent *self);
 
 PhotosTrackerChangeEventType photos_tracker_change_event_get_type (PhotosTrackerChangeEvent *self);
diff --git a/src/photos-tracker-change-monitor.c b/src/photos-tracker-change-monitor.c
index 2f9aa90..a7cfe69 100644
--- a/src/photos-tracker-change-monitor.c
+++ b/src/photos-tracker-change-monitor.c
@@ -96,7 +96,7 @@ photos_tracker_change_monitor_query_data_free (PhotosTrackerChangeMonitorQueryDa
     g_hash_table_unref (data->id_table);
 
   if (data->events != NULL)
-    g_queue_free (data->events);
+    g_queue_free_full (data->events, (GDestroyNotify) photos_tracker_change_event_free);
 
   g_slice_free (PhotosTrackerChangeMonitorQueryData, data);
 }
@@ -129,12 +129,9 @@ photos_tracker_change_monitor_add_event (PhotosTrackerChangeMonitor *self, Photo
   old_change_event = (PhotosTrackerChangeEvent *) g_hash_table_lookup (priv->pending_changes, urn);
 
   if (old_change_event != NULL)
-    {
-      photos_tracker_change_event_merge (old_change_event, change_event);
-      photos_tracker_change_event_free (change_event);
-    }
+    photos_tracker_change_event_merge (old_change_event, change_event);
   else
-    g_hash_table_insert (priv->pending_changes, g_strdup (urn), change_event);
+    g_hash_table_insert (priv->pending_changes, g_strdup (urn), photos_tracker_change_event_copy 
(change_event));
 }
 
 
@@ -159,7 +156,7 @@ photos_tracker_change_monitor_send_events (PhotosTrackerChangeMonitor *self, GHa
       urn = (gchar *) g_hash_table_lookup (id_table, GINT_TO_POINTER (urn_id));
 
       photos_tracker_change_event_set_resolved_values (change_event, urn, predicate);
-      photos_tracker_change_monitor_add_event (self, change_event); /* steals change_event */
+      photos_tracker_change_monitor_add_event (self, change_event);
     }
 
   g_signal_emit (self, signals[CHANGES_PENDING], 0, priv->pending_changes);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]