diff options
author | Cosimo Cecchi <cosimo.cecchi@collabora.co.uk> | 2009-10-15 19:43:44 +0800 |
---|---|---|
committer | Cosimo Cecchi <cosimo.cecchi@collabora.co.uk> | 2009-10-15 19:53:57 +0800 |
commit | 04695319095535fc816b62c3054ac514fb64d830 (patch) | |
tree | 745de3ed4e53ab13046ff1da6ea82c0c9c7b6cdf /libempathy-gtk/empathy-avatar-chooser.c | |
parent | 837805764a983cb16665c1a61c601aeddd595eb4 (diff) | |
download | gsoc2013-empathy-04695319095535fc816b62c3054ac514fb64d830.tar gsoc2013-empathy-04695319095535fc816b62c3054ac514fb64d830.tar.gz gsoc2013-empathy-04695319095535fc816b62c3054ac514fb64d830.tar.bz2 gsoc2013-empathy-04695319095535fc816b62c3054ac514fb64d830.tar.lz gsoc2013-empathy-04695319095535fc816b62c3054ac514fb64d830.tar.xz gsoc2013-empathy-04695319095535fc816b62c3054ac514fb64d830.tar.zst gsoc2013-empathy-04695319095535fc816b62c3054ac514fb64d830.zip |
Don't try to double free the avatar data (#598423).
Also, simplify the code for loading the avatar data from the file.
Diffstat (limited to 'libempathy-gtk/empathy-avatar-chooser.c')
-rw-r--r-- | libempathy-gtk/empathy-avatar-chooser.c | 42 |
1 files changed, 11 insertions, 31 deletions
diff --git a/libempathy-gtk/empathy-avatar-chooser.c b/libempathy-gtk/empathy-avatar-chooser.c index af96885e4..b28ed2627 100644 --- a/libempathy-gtk/empathy-avatar-chooser.c +++ b/libempathy-gtk/empathy-avatar-chooser.c @@ -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); |