[Xfce4-commits] <xfdesktop:eric/settings-changes> Fix some memory leaks
Eric Koegel
noreply at xfce.org
Sun Oct 27 09:06:01 CET 2013
Updating branch refs/heads/eric/settings-changes
to 2f9278f47973b337f52619afece20cf498664fd6 (commit)
from 715985a0cfdcabe4eacc391c8f37690d343351e7 (commit)
commit 2f9278f47973b337f52619afece20cf498664fd6
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Sun Oct 27 09:29:43 2013 +0300
Fix some memory leaks
common/xfdesktop-thumbnailer.c | 38 +++++++++++++++++++++++++++---------
src/xfce-backdrop.c | 39 ++++++++++++++++++++++++++-----------
src/xfce-desktop.c | 30 ++++++++++++++++------------
src/xfce-workspace.c | 2 ++
src/xfdesktop-file-icon-manager.c | 17 +++++++++++++---
5 files changed, 91 insertions(+), 35 deletions(-)
diff --git a/common/xfdesktop-thumbnailer.c b/common/xfdesktop-thumbnailer.c
index 2416d8b..248a3c5 100644
--- a/common/xfdesktop-thumbnailer.c
+++ b/common/xfdesktop-thumbnailer.c
@@ -340,7 +340,7 @@ xfdesktop_thumbnailer_queue_thumbnail(XfdesktopThumbnailer *thumbnailer,
if(g_slist_find(thumbnailer->priv->queue, file) == NULL) {
thumbnailer->priv->queue = g_slist_prepend(thumbnailer->priv->queue,
- file);
+ g_strdup(file));
}
thumbnailer->priv->request_timer_id = g_timeout_add_full(
@@ -370,6 +370,8 @@ void
xfdesktop_thumbnailer_dequeue_thumbnail(XfdesktopThumbnailer *thumbnailer,
gchar *file)
{
+ GSList *item;
+
g_return_if_fail(XFDESKTOP_IS_THUMBNAILER(thumbnailer));
g_return_if_fail(file != NULL);
@@ -392,9 +394,11 @@ xfdesktop_thumbnailer_dequeue_thumbnail(XfdesktopThumbnailer *thumbnailer,
thumbnailer->priv->handle = 0;
}
- if(g_slist_find(thumbnailer->priv->queue, file) != NULL) {
- thumbnailer->priv->queue = g_slist_remove_all(thumbnailer->priv->queue,
- file);
+ item = g_slist_find(thumbnailer->priv->queue, file);
+ if(item != NULL) {
+ g_free(item->data);
+ thumbnailer->priv->queue = g_slist_remove(thumbnailer->priv->queue,
+ file);
}
thumbnailer->priv->request_timer_id = g_timeout_add_full(
@@ -436,6 +440,7 @@ xfdesktop_thumbnailer_queue_request_timer(XfdesktopThumbnailer *thumbnailer)
file = g_file_new_for_path(iter->data);
uris[i] = g_file_get_uri(file);
mimetypes[i] = xfdesktop_get_file_mimetype(iter->data);
+
g_object_unref(file);
}
iter = g_slist_next(iter);
@@ -465,6 +470,18 @@ xfdesktop_thumbnailer_queue_request_timer(XfdesktopThumbnailer *thumbnailer)
}
}
+ /* Free the memory */
+ i = 0;
+ iter = thumbnailer->priv->queue;
+ while(iter) {
+ if(iter->data) {
+ g_free(uris[i]);
+ g_free(mimetypes[i]);
+ }
+ iter = g_slist_next(iter);
+ i++;
+ }
+
g_free(uris);
g_free(mimetypes);
@@ -498,7 +515,7 @@ xfdesktop_thumbnailer_thumbnail_ready_dbus(DBusGProxy *proxy,
gchar *thumbnail_location;
GFile *file;
GSList *iter = thumbnailer->priv->queue;
- gchar *f_uri, *f_uri_checksum, *filename;
+ gchar *f_uri, *f_uri_checksum, *filename, *temp;
gchar *thumbnail_flavor;
gint x = 0;
@@ -531,8 +548,8 @@ xfdesktop_thumbnailer_thumbnail_ready_dbus(DBusGProxy *proxy,
filename, NULL);
DBG("thumbnail-ready src: %s thumbnail: %s",
- (char*)iter->data,
- thumbnail_location);
+ (char*)iter->data,
+ thumbnail_location);
g_signal_emit(G_OBJECT(thumbnailer),
thumbnailer_signals[THUMBNAIL_READY],
@@ -540,14 +557,17 @@ xfdesktop_thumbnailer_thumbnail_ready_dbus(DBusGProxy *proxy,
iter->data,
thumbnail_location);
+ temp = iter->data;
thumbnailer->priv->queue = g_slist_remove(thumbnailer->priv->queue,
- iter->data);
+ temp);
iter = thumbnailer->priv->queue;
x++;
-
+
g_free(filename);
g_free(f_uri_checksum);
+ g_free(thumbnail_location);
+ g_free(temp);
} else {
iter = g_slist_next(iter);
}
diff --git a/src/xfce-backdrop.c b/src/xfce-backdrop.c
index 14ce700..929c6ee 100644
--- a/src/xfce-backdrop.c
+++ b/src/xfce-backdrop.c
@@ -240,29 +240,36 @@ xfce_backdrop_clear_cached_image(XfceBackdrop *backdrop)
backdrop->priv->pix = NULL;
}
+/* Returns a GList of all the files in the parent directory of filename */
static GList *
-list_files_in_dir(const gchar *path)
+list_files_in_dir(const gchar *filename)
{
GDir *dir;
gboolean needs_slash = TRUE;
const gchar *file;
GList *files = NULL;
+ gchar *dir_name;
- dir = g_dir_open(path, 0, 0);
- if(!dir)
+ dir_name = g_path_get_dirname(filename);
+
+ dir = g_dir_open(dir_name, 0, 0);
+ if(!dir) {
+ g_free(dir_name);
return NULL;
+ }
- if(path[strlen(path)-1] == '/')
+ if(dir_name[strlen(dir_name)-1] == '/')
needs_slash = FALSE;
while((file = g_dir_read_name(dir))) {
gchar *current_file = g_strdup_printf(needs_slash ? "%s/%s" : "%s%s",
- path, file);
+ dir_name, file);
files = g_list_insert_sorted(files, current_file, (GCompareFunc)g_strcmp0);
}
g_dir_close(dir);
+ g_free(dir_name);
return files;
}
@@ -280,8 +287,10 @@ xfce_backdrop_choose_next(const gchar *filename)
g_return_val_if_fail(filename, NULL);
/* We don't cache the list at all. This way the user can add/remove items
- * whenever they like without xfdesktop having to do anything */
- files = list_files_in_dir(g_path_get_dirname(filename));
+ * whenever they like without xfdesktop having to do anything. If we start
+ * supporting sub-directories we may want to re-think that assumption */
+ files = list_files_in_dir(filename);
+
if(!files)
return NULL;
@@ -331,8 +340,10 @@ xfce_backdrop_choose_random(const gchar *filename)
g_return_val_if_fail(filename, NULL);
/* We don't cache the list at all. This way the user can add/remove items
- * whenever they like without xfdesktop having to do anything */
- files = list_files_in_dir(g_path_get_dirname(filename));
+ * whenever they like without xfdesktop having to do anything. If we start
+ * supporting sub-directories we may want to re-think that assumption */
+ files = list_files_in_dir(filename);
+
if(!files)
return NULL;
@@ -389,7 +400,8 @@ xfce_backdrop_choose_chronological(const gchar *filename)
/* We don't cache the list at all. This way the user can add/remove items
* whenever they like without xfdesktop having to do anything. If we start
* supporting sub-directories we may want to re-think that assumption */
- files = list_files_in_dir(g_path_get_dirname(filename));
+ files = list_files_in_dir(filename);
+
if(!files)
return NULL;
@@ -908,7 +920,7 @@ xfce_backdrop_get_image_style(XfceBackdrop *backdrop)
*
* Sets the image that should be used with the #XfceBackdrop. The image will
* be composited on top of the color (or color gradient). To clear the image,
- * use this call with a @filename argument of %NULL.
+ * use this call with a @filename argument of %NULL. Makes a copy of @filename.
**/
void
xfce_backdrop_set_image_filename(XfceBackdrop *backdrop, const gchar *filename)
@@ -973,6 +985,8 @@ xfce_backdrop_cycle_backdrop(XfceBackdrop *backdrop)
xfce_backdrop_set_image_filename(backdrop, new_backdrop);
g_signal_emit(G_OBJECT(backdrop), backdrop_signals[BACKDROP_CYCLE], 0);
}
+
+ g_free(new_backdrop);
}
static gboolean
@@ -1614,6 +1628,9 @@ xfce_backdrop_file_ready_cb(GObject *source_object,
TRACE("entering");
+ /* Finished with the file, clean it up */
+ g_object_unref(file);
+
/* If this fails then close the loader, it will only display the selected
* backdrop color */
if(input_stream == NULL) {
diff --git a/src/xfce-desktop.c b/src/xfce-desktop.c
index e7d5b45..d59a92a 100644
--- a/src/xfce-desktop.c
+++ b/src/xfce-desktop.c
@@ -366,7 +366,10 @@ backdrop_changed_cb(XfceBackdrop *backdrop, gpointer user_data)
GdkRectangle rect;
GdkRegion *clip_region = NULL;
gint i, monitor = -1, current_workspace;
-
+#ifdef G_ENABLE_DEBUG
+ gchar *monitor_name = NULL;
+#endif
+
TRACE("entering");
g_return_if_fail(XFCE_IS_DESKTOP(desktop));
@@ -395,9 +398,13 @@ backdrop_changed_cb(XfceBackdrop *backdrop, gpointer user_data)
if(monitor == -1)
return;
+#ifdef G_ENABLE_DEBUG
+ monitor_name = gdk_screen_get_monitor_plug_name(gscreen, monitor);
+
+ DBG("backdrop changed for workspace %d, monitor %d (%s)", current_workspace, monitor, monitor_name);
- DBG("backdrop changed for workspace %d, monitor %d (%s)",
- current_workspace, monitor, gdk_screen_get_monitor_plug_name(gscreen, monitor));
+ g_free(monitor_name);
+#endif
if(xfce_desktop_get_n_monitors(desktop) > 1
&& xfce_workspace_get_xinerama_stretch(desktop->priv->workspaces[current_workspace])) {
@@ -864,7 +871,7 @@ static void
xfce_desktop_finalize(GObject *object)
{
XfceDesktop *desktop = XFCE_DESKTOP(object);
-
+
g_object_unref(G_OBJECT(desktop->priv->channel));
g_free(desktop->priv->property_prefix);
@@ -1055,14 +1062,13 @@ xfce_desktop_unrealize(GtkWidget *widget)
gchar property_name[128];
g_return_if_fail(XFCE_IS_DESKTOP(desktop));
-
- if(gtk_major_version > 2
- || (gtk_major_version == 2 && gtk_minor_version >= 13))
- {
- g_signal_handlers_disconnect_by_func(G_OBJECT(desktop->priv->gscreen),
- G_CALLBACK(xfce_desktop_monitors_changed),
- desktop);
- }
+
+ /* disconnect all the xfconf settings to this desktop */
+ xfconf_g_property_unbind_all(G_OBJECT(desktop));
+
+ g_signal_handlers_disconnect_by_func(G_OBJECT(desktop->priv->gscreen),
+ G_CALLBACK(xfce_desktop_monitors_changed),
+ desktop);
if(gtk_widget_get_mapped(widget))
gtk_widget_unmap(widget);
diff --git a/src/xfce-workspace.c b/src/xfce-workspace.c
index b9f5cf8..68339ef 100644
--- a/src/xfce-workspace.c
+++ b/src/xfce-workspace.c
@@ -160,6 +160,8 @@ xfce_workspace_change_backdrop(XfceWorkspace *workspace,
} else {
g_snprintf(buf, sizeof(buf), "%smonitor%s/workspace%d/last-image",
workspace->priv->property_prefix, monitor_name, workspace->priv->workspace_num);
+
+ g_free(monitor_name);
}
/* Update the property so that xfdesktop won't show the same image every
diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 815562f..63d00c4 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -2027,11 +2027,18 @@ xfdesktop_file_icon_manager_queue_thumbnail(XfdesktopFileIconManager *fmanager,
GFile *temp = g_file_new_for_path(thumbnail_file);
xfdesktop_icon_set_thumbnail_file(XFDESKTOP_ICON(icon), temp);
}
+
+ g_free(thumbnail_file);
} else {
xfdesktop_thumbnailer_queue_thumbnail(fmanager->priv->thumbnailer,
path);
}
}
+
+ if(path) {
+ g_free(path);
+ path = NULL;
+ }
}
/* Adds a single icon to the icon view, popping from the top of the stack.
@@ -2688,6 +2695,8 @@ xfdesktop_file_icon_manager_files_ready(GFileEnumerator *enumerator,
g_signal_connect(fmanager->priv->metadata_monitor, "changed",
G_CALLBACK(xfdesktop_file_icon_manager_metadata_changed),
fmanager);
+
+ g_object_unref(metadata_location);
g_free(location);
}
} else {
@@ -2807,11 +2816,11 @@ static void
xfdesktop_file_icon_manager_load_removable_media(XfdesktopFileIconManager *fmanager)
{
GList *volumes, *l;
-
+
/* ensure we don't re-enter if we're already set up */
if(fmanager->priv->removable_icons)
return;
-
+
if(!fmanager->priv->volume_monitor)
fmanager->priv->volume_monitor = g_volume_monitor_get();
@@ -3747,6 +3756,8 @@ xfdesktop_file_icon_manager_update_image(GtkWidget *widget,
{
g_object_unref(file);
file = g_file_new_for_path(thumbfile);
- xfdesktop_icon_set_thumbnail_file(icon, file);
+ xfdesktop_icon_set_thumbnail_file(icon, g_object_ref(file));
}
+
+ g_object_unref(file);
}
More information about the Xfce4-commits
mailing list