Mercurial > pidgin.yaz
diff pidgin/gtkrequest.c @ 32156:1693114a2655
applied changes from 6cf1aee8ac5e3c836af832eaf26ccedd611dc70b
through e802003adbf0be4496de3de8ac03b47c1e471d00
Original commit message:
Start looking at the GError parameter every time we call these functions:
- gdk_pixbuf_loader_write
- gdk_pixbuf_loader_close
- gdk_pixbuf_new_from_file
- gdk_pixbuf_new_from_file_at_size
- gdk_pixbuf_new_from_file_at_scale
There are times when gdkpixbuf returns a semi-invalid GdkPixbuf object and
also sets the GError. If this happens we want to discard and ignore the
GdkPixbuf object because it can cause problems. For example, calling
gdk_pixbuf_scale_simple() causes gdkpixbuf to rapidly consume memory in
an infinite loop. And that's bad.
This commit adds some helper functions to gtkutils.[c|h] that make it a
little easier to check the GError value. We should use them everywhere
we call any of the above functions.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 22 Jun 2011 07:09:42 +0000 |
parents | f56b66606fd2 |
children | 142429bcb4c8 |
line wrap: on
line diff
--- a/pidgin/gtkrequest.c Wed Jun 22 02:48:46 2011 +0000 +++ b/pidgin/gtkrequest.c Wed Jun 22 07:09:42 2011 +0000 @@ -653,35 +653,30 @@ /* Dialog icon. */ if (icon_data) { - GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); - GdkPixbuf *pixbuf = NULL; - if (gdk_pixbuf_loader_write(loader, icon_data, icon_size, NULL)) { - pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); - if (pixbuf) { - /* scale the image if it is too large */ - int width = gdk_pixbuf_get_width(pixbuf); - int height = gdk_pixbuf_get_height(pixbuf); - if (width > 128 || height > 128) { - int scaled_width = width > height ? 128 : (128 * width) / height; - int scaled_height = height > width ? 128 : (128 * height) / width; - GdkPixbuf *scaled = - gdk_pixbuf_scale_simple(pixbuf, scaled_width, scaled_height, - GDK_INTERP_BILINEAR); + GdkPixbuf *pixbuf = pidgin_pixbuf_from_data(icon_data, icon_size); + if (pixbuf) { + /* scale the image if it is too large */ + int width = gdk_pixbuf_get_width(pixbuf); + int height = gdk_pixbuf_get_height(pixbuf); + if (width > 128 || height > 128) { + int scaled_width = width > height ? 128 : (128 * width) / height; + int scaled_height = height > width ? 128 : (128 * height) / width; + GdkPixbuf *scaled = + gdk_pixbuf_scale_simple(pixbuf, scaled_width, scaled_height, + GDK_INTERP_BILINEAR); - purple_debug_info("pidgin", - "dialog icon was too large, scale it down\n"); - if (scaled) { - g_object_unref(pixbuf); - pixbuf = scaled; - } + purple_debug_info("pidgin", + "dialog icon was too large, scaled it down\n"); + if (scaled) { + g_object_unref(pixbuf); + pixbuf = scaled; } - img = gtk_image_new_from_pixbuf(pixbuf); } + img = gtk_image_new_from_pixbuf(pixbuf); + g_object_unref(pixbuf); } else { purple_debug_info("pidgin", "failed to parse dialog icon\n"); } - gdk_pixbuf_loader_close(loader, NULL); - g_object_unref(loader); } if (!img) { @@ -1016,22 +1011,17 @@ { GtkWidget *widget; GdkPixbuf *buf, *scale; - GdkPixbufLoader *loader; - loader = gdk_pixbuf_loader_new(); - gdk_pixbuf_loader_write(loader, - (const guchar *)purple_request_field_image_get_buffer(field), - purple_request_field_image_get_size(field), - NULL); - gdk_pixbuf_loader_close(loader, NULL); - buf = gdk_pixbuf_loader_get_pixbuf(loader); + buf = pidgin_pixbuf_from_data( + (const guchar *)purple_request_field_image_get_buffer(field), + purple_request_field_image_get_size(field)); scale = gdk_pixbuf_scale_simple(buf, purple_request_field_image_get_scale_x(field) * gdk_pixbuf_get_width(buf), purple_request_field_image_get_scale_y(field) * gdk_pixbuf_get_height(buf), GDK_INTERP_BILINEAR); widget = gtk_image_new_from_pixbuf(scale); - g_object_unref(G_OBJECT(loader)); + g_object_unref(G_OBJECT(buf)); g_object_unref(G_OBJECT(scale)); return widget; @@ -1132,7 +1122,7 @@ GdkPixbuf* pixbuf = NULL; if (icon_path) - pixbuf = gdk_pixbuf_new_from_file(icon_path, NULL); + pixbuf = pidgin_pixbuf_new_from_file(icon_path); gtk_list_store_set(store, &iter, 0, purple_request_field_list_get_data(field, text),