# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: geoffrey.antos@gmail.com-20080831211530-\
#   eexa6wd0nd8a2e15
# target_branch: ../upstream/
# testament_sha1: 7fdc7ee81e5a3b72581cec2510f0c076f0bde1a0
# timestamp: 2008-08-31 14:16:21 -0700
# source_branch: .
# base_revision_id: geoffrey.antos@gmail.com-20080831205857-\
#   4t5hrq0sc8x4vk53
# 
# Begin patch
=== modified file 'ChangeLog'
--- ChangeLog	2008-08-31 19:57:35 +0000
+++ ChangeLog	2008-08-31 21:15:30 +0000
@@ -1,3 +1,13 @@
+2008-08-30  Geoffrey Antos <dynamotwain@aim.com>
+
+	* 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):
+		Avoid dereferencing NULL pointers.
+
 2008-08-21  Michael J. Chudobiak  <mjc@svn.gnome.org>
 
 	* libgthumb/gfile-utils.c:

=== modified file 'libgthumb/image-loader.c'
--- libgthumb/image-loader.c	2008-08-11 06:40:05 +0000
+++ libgthumb/image-loader.c	2008-08-31 21:15:30 +0000
@@ -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 file 'libgthumb/image-viewer-image.c'
--- libgthumb/image-viewer-image.c	2008-08-07 20:11:34 +0000
+++ libgthumb/image-viewer-image.c	2008-08-31 21:15:30 +0000
@@ -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 file 'libgthumb/image-viewer.c'
--- libgthumb/image-viewer.c	2008-08-11 06:40:05 +0000
+++ libgthumb/image-viewer.c	2008-08-31 21:15:30 +0000
@@ -1504,7 +1504,9 @@
 	image_loader_set_pixbuf (priv->loader, pixbuf);
 	create_image (ivl_data->viewer);
 
-	g_object_unref (G_OBJECT (pixbuf));
+	if (pixbuf != NULL)
+		g_object_unref (G_OBJECT (pixbuf));
+
 	g_free (ivl_data);
 
 }
@@ -1524,7 +1526,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,

