From ec4241a80b029d0bb13d3f95a963d5f7bd5acd1a Mon Sep 17 00:00:00 2001 From: Yi-Soo An Date: Sun, 17 Mar 2019 20:31:14 +0900 Subject: [PATCH 1/2] bookmark-list: Clean up code Clean up do_finalize method to use NautilusBookmarkList object instead of casting to itself every lines. --- src/nautilus-bookmark-list.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/nautilus-bookmark-list.c b/src/nautilus-bookmark-list.c index ad25b66d61..6a6162a0ac 100644 --- a/src/nautilus-bookmark-list.c +++ b/src/nautilus-bookmark-list.c @@ -162,15 +162,17 @@ clear (NautilusBookmarkList *bookmarks) static void do_finalize (GObject *object) { - if (NAUTILUS_BOOKMARK_LIST (object)->monitor != NULL) + NautilusBookmarkList *self = NAUTILUS_BOOKMARK_LIST (object); + + if (self->monitor != NULL) { - g_file_monitor_cancel (NAUTILUS_BOOKMARK_LIST (object)->monitor); - NAUTILUS_BOOKMARK_LIST (object)->monitor = NULL; + g_file_monitor_cancel (self->monitor); + self->monitor = NULL; } - g_queue_free (NAUTILUS_BOOKMARK_LIST (object)->pending_ops); + g_queue_free (self->pending_ops); - clear (NAUTILUS_BOOKMARK_LIST (object)); + clear (self); G_OBJECT_CLASS (nautilus_bookmark_list_parent_class)->finalize (object); } -- GitLab From 179e0bfaddcf29d8a7f8074cc924d5aa45b1a954 Mon Sep 17 00:00:00 2001 From: Yi-Soo An Date: Sun, 17 Mar 2019 20:37:46 +0900 Subject: [PATCH 2/2] bookmark-list: Fix memory leak According to the documentation[1], GFileMonitor object must be freed when it is not necessary. g_file_monitor_cancel() doesn't free the object. [1]: https://developer.gnome.org/gio/stable/GFile.html#g-file-monitor-file --- src/nautilus-bookmark-list.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nautilus-bookmark-list.c b/src/nautilus-bookmark-list.c index 6a6162a0ac..0f8526ba64 100644 --- a/src/nautilus-bookmark-list.c +++ b/src/nautilus-bookmark-list.c @@ -167,7 +167,7 @@ do_finalize (GObject *object) if (self->monitor != NULL) { g_file_monitor_cancel (self->monitor); - self->monitor = NULL; + g_clear_object (&self->monitor); } g_queue_free (self->pending_ops); @@ -510,7 +510,7 @@ save_file_async (NautilusBookmarkList *self) if (self->monitor != NULL) { g_file_monitor_cancel (self->monitor); - self->monitor = NULL; + g_clear_object (&self->monitor); } for (l = self->list; l; l = l->next) -- GitLab