[empathy] libempathy-gtk: Explicitly close the input stream used for reading avatars



commit 57075092737c287010e1a2435bf1b1c1839101a5
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Aug 23 23:42:52 2011 +0100

    libempathy-gtk: Explicitly close the input stream used for reading avatars
    
    Due to a missing unref in GIO, the input stream is leaked by GFileIcon, so
    if we rely on its FD being implicitly closed when the stream is finalised,
    we'll end up leaking (lots of) file descriptors.
    
    As well as fixing the unref in GIO (see: bgo#657206), we now explicitly
    close the input stream so that even if the stream object is leaked, the FD
    isn't.
    
    Closes: bgo#656682

 libempathy-gtk/empathy-ui-utils.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 060e0aa..2a4b867 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -566,6 +566,21 @@ pixbuf_avatar_from_individual_closure_free (
 }
 
 static void
+avatar_icon_load_close_cb (GObject      *object,
+                           GAsyncResult *result,
+                           gpointer      user_data)
+{
+	GError *error = NULL;
+
+	g_input_stream_close_finish (G_INPUT_STREAM (object), result, &error);
+
+	if (error != NULL) {
+		DEBUG ("Failed to close pixbuf stream: %s", error->message);
+		g_error_free (error);
+	}
+}
+
+static void
 avatar_icon_load_read_cb (GObject      *object,
                           GAsyncResult *result,
                           gpointer      user_data)
@@ -607,6 +622,11 @@ avatar_icon_load_read_cb (GObject      *object,
 			avatar_pixbuf_from_loader (closure->loader),
 			g_object_unref);
 
+		/* Close the file for safety (even though it should be
+		 * automatically closed when the stream is finalised). */
+		g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, NULL,
+			(GAsyncReadyCallback) avatar_icon_load_close_cb, NULL);
+
 		goto out;
 	} else {
 		/* Loop round and read another chunk. */



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