]> git.0d.be Git - empathy.git/commitdiff
Don't try to double free the avatar data (#598423).
authorCosimo Cecchi <cosimo.cecchi@collabora.co.uk>
Thu, 15 Oct 2009 11:43:44 +0000 (13:43 +0200)
committerCosimo Cecchi <cosimo.cecchi@collabora.co.uk>
Thu, 15 Oct 2009 11:51:30 +0000 (13:51 +0200)
Also, simplify the code for loading the avatar data from the file.

libempathy-gtk/empathy-avatar-chooser.c

index af96885e4f6e9b0d2e434263ea120b5e2e9df0ba..b28ed2627d1358a1be2f9edc835fc3ff77ce1088 100644 (file)
@@ -594,6 +594,7 @@ avatar_chooser_set_image_from_data (EmpathyAvatarChooser *chooser,
        pixbuf = empathy_pixbuf_from_data_and_mime (data, size, &mime_type);
        if (pixbuf == NULL) {
                g_free (data);
+               data = NULL;
                return;
        }
 
@@ -789,9 +790,9 @@ avatar_chooser_drag_data_received_cb (GtkWidget          *widget,
        target_type = gdk_atom_name (gtk_selection_data_get_target (selection_data));
        if (!strcmp (target_type, URI_LIST_TYPE)) {
                GFile            *file;
-               GFileInputStream *input_stream;
                gchar            *nl;
                gchar            *data = NULL;
+               gsize             bytes_read;
 
                nl = strstr (gtk_selection_data_get_data (selection_data), "\r\n");
                if (nl) {
@@ -806,37 +807,16 @@ avatar_chooser_drag_data_received_cb (GtkWidget          *widget,
                        file = g_file_new_for_uri (gtk_selection_data_get_data (selection_data));
                }
 
-               input_stream = g_file_read (file, NULL, NULL);
-
-               if (input_stream != NULL) {
-                       GFileInfo *info;
-
-                       info = g_file_query_info (file,
-                                                 G_FILE_ATTRIBUTE_STANDARD_SIZE,
-                                                 0, NULL, NULL);
-                       if (info != NULL) {
-                               goffset size;
-                               gssize bytes_read;
-
-                               size = g_file_info_get_size (info);
-                               data = g_malloc (size);
-
-                               bytes_read = g_input_stream_read (G_INPUT_STREAM (input_stream),
-                                                                 data, size,
-                                                                 NULL, NULL);
-                               if (bytes_read != -1) {
-                                       avatar_chooser_set_image_from_data (
-                                               chooser, data,
-                                               (gsize) bytes_read,
-                                               TRUE);
-                                       handled = TRUE;
-                               }
-
-                               g_free (data);
-                               g_object_unref (info);
-                       }
+               handled = g_file_load_contents (file, NULL, &data, &bytes_read,
+                                               NULL, NULL);
 
-                       g_object_unref (input_stream);
+               if (handled) {
+                       /* this in turn calls empathy_avatar_new(), which assumes
+                        * ownership of data.
+                        */
+                       avatar_chooser_set_image_from_data (chooser, data,
+                                                           bytes_read,
+                                                           TRUE);
                }
 
                g_object_unref (file);