gthumb r2409 - in trunk: . libgthumb



Author: mjc
Date: Thu Sep 11 12:41:28 2008
New Revision: 2409
URL: http://svn.gnome.org/viewvc/gthumb?rev=2409&view=rev

Log:
2008-09-11  Michael J. Chudobiak  <mjc svn gnome org>

        * libgthumb/image-loader.c: (image_loader_set_pixbuf)
        Allow setting the pixbuf to NULL.

        * libgthumb/image-viewer-image.c: (create_pixbuf_from_iter),
        (image_viewer_image_new), (pixbuf_to_surface):
        * libgthumb/image-viewer.c: (set_pixbuf__step2),
        (image_viewer_set_pixbuf), (image_viewer_set_void):
        Avoid dereferencing NULL pointers.

        Fixes regression from bug #501512. Patch by 
        Geoffrey Antos <dynamotwain aim com>.



Modified:
   trunk/ChangeLog
   trunk/libgthumb/image-loader.c
   trunk/libgthumb/image-viewer-image.c
   trunk/libgthumb/image-viewer.c

Modified: trunk/libgthumb/image-loader.c
==============================================================================
--- trunk/libgthumb/image-loader.c	(original)
+++ trunk/libgthumb/image-loader.c	Thu Sep 11 12:41:28 2008
@@ -414,7 +414,6 @@
 			 GdkPixbuf   *pixbuf)
 {
 	g_return_if_fail (il != NULL);
-	g_return_if_fail (pixbuf != NULL);
 
 	g_mutex_lock (il->priv->data_mutex);
 	if (il->priv->animation != NULL) {
@@ -425,10 +424,10 @@
 		g_object_unref (il->priv->pixbuf);
 		il->priv->pixbuf = NULL;
 	}
+
+	il->priv->pixbuf = pixbuf;
 	if (pixbuf != NULL) {
 		g_object_ref (pixbuf);
-		il->priv->pixbuf = pixbuf;
-		/*il->priv->pixbuf = gdk_pixbuf_copy (pixbuf);*/
 	}
 	g_mutex_unlock (il->priv->data_mutex);
 }

Modified: trunk/libgthumb/image-viewer-image.c
==============================================================================
--- trunk/libgthumb/image-viewer-image.c	(original)
+++ trunk/libgthumb/image-viewer-image.c	Thu Sep 11 12:41:28 2008
@@ -200,12 +200,14 @@
 	priv->anim_pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (iter);
 	priv->frame_delay = gdk_pixbuf_animation_iter_get_delay_time (iter);
 
-	if (priv->buffer != NULL)
-	{
+	if (priv->buffer != NULL) {
 		cairo_surface_destroy (priv->buffer);
+		priv->buffer = NULL;
 	}
 
-	priv->buffer = pixbuf_to_surface (priv->anim_pixbuf);
+	if (priv->anim_pixbuf != NULL) {
+		priv->buffer = pixbuf_to_surface (priv->anim_pixbuf);
+	}
 
 	gtk_widget_queue_draw (GTK_WIDGET (priv->viewer));
 }
@@ -418,13 +420,11 @@
 	priv->is_animation = (priv->anim != NULL) &&
 		! gdk_pixbuf_animation_is_static_image (priv->anim);
 
-	if (priv->is_animation)
-	{
+	if (priv->is_animation) {
 		create_first_pixbuf (image);
 		add_change_frame_timeout(image);
 	}
-	else
-	{
+	else if (priv->static_pixbuf != NULL) {
 		priv->buffer = pixbuf_to_surface (priv->static_pixbuf);
 	}
 
@@ -898,11 +898,11 @@
 pixbuf_to_surface (GdkPixbuf *pixbuf)
 {
 	/* based on gdk_cairo_set_source_pixbuf */
-	gint    width = gdk_pixbuf_get_width (pixbuf);
-	gint    height = gdk_pixbuf_get_height (pixbuf);
-	guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
-	int     gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
-	int     n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+	gint    width;
+	gint    height;
+	guchar *gdk_pixels;
+	int     gdk_rowstride;
+	int     n_channels;
 	int     cairo_stride;
 	guchar *cairo_pixels;
 	cairo_format_t format;
@@ -910,6 +910,14 @@
 	static const cairo_user_data_key_t key;
 	int j;
 
+	g_return_val_if_fail (pixbuf != NULL, NULL);
+
+	width = gdk_pixbuf_get_width (pixbuf);
+	height = gdk_pixbuf_get_height (pixbuf);
+	gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
+	gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+	n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+
 	if (n_channels == 3)
 		format = CAIRO_FORMAT_RGB24;
 	else

Modified: trunk/libgthumb/image-viewer.c
==============================================================================
--- trunk/libgthumb/image-viewer.c	(original)
+++ trunk/libgthumb/image-viewer.c	Thu Sep 11 12:41:28 2008
@@ -1366,7 +1366,9 @@
 	image_loader_set_pixbuf (priv->loader, pixbuf);
 	create_image (priv->loader, ivl_data->viewer);
 
-	g_object_unref (G_OBJECT (pixbuf));
+	if (pixbuf != NULL)
+		g_object_unref (G_OBJECT (pixbuf));
+
 	g_free (ivl_data);
 
 }
@@ -1386,7 +1388,8 @@
 	ivl_data = g_new0 (ImageViewerLoadData, 1);
 	ivl_data->viewer = viewer;
 	ivl_data->data = pixbuf;
-	g_object_ref (G_OBJECT (pixbuf));
+	if (pixbuf != NULL)
+		g_object_ref (G_OBJECT (pixbuf));
 
 	image_loader_stop (priv->loader,
 			   (DoneFunc) set_pixbuf__step2,
@@ -1404,10 +1407,11 @@
 
 	priv = IMAGE_VIEWER_GET_PRIVATE (viewer);
 
-	g_object_unref (priv->image);
-	priv->image = NULL;
-
-	gtk_widget_queue_resize (GTK_WIDGET (viewer));
+	if (priv->image) {
+		g_object_unref (priv->image);
+		priv->image = NULL;
+		gtk_widget_queue_resize (GTK_WIDGET (viewer));
+	}
 }
 
 



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