]> git.0d.be Git - empathy.git/commitdiff
libempathy-gtk: Explicitly close the input stream used for reading avatars
authorPhilip Withnall <philip@tecnocode.co.uk>
Tue, 23 Aug 2011 22:42:52 +0000 (23:42 +0100)
committerPhilip Withnall <philip@tecnocode.co.uk>
Tue, 23 Aug 2011 22:47:23 +0000 (23:47 +0100)
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

index 060e0aab58dfe4c0237628e0c9c96cfa7277ca13..2a4b867815c1c04f949c7a7a6771e7606499551f 100644 (file)
@@ -565,6 +565,21 @@ pixbuf_avatar_from_individual_closure_free (
        g_free (closure);
 }
 
+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,
@@ -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. */