[gthumb] copy the pixbuf data before saving to avoid data corruption



commit 721d426819edd1568b795bf7e699234eef1f139f
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jun 29 20:16:41 2010 +0200

    copy the pixbuf data before saving to avoid data corruption

 extensions/resize_images/dlg-resize-images.c |    3 +--
 gthumb/gth-pixbuf-list-task.c                |    1 +
 gthumb/pixbuf-io.c                           |    8 ++++++--
 3 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/extensions/resize_images/dlg-resize-images.c b/extensions/resize_images/dlg-resize-images.c
index 22d7ada..0d217ea 100644
--- a/extensions/resize_images/dlg-resize-images.c
+++ b/extensions/resize_images/dlg-resize-images.c
@@ -103,8 +103,7 @@ resize_step (GthPixbufTask *pixbuf_task)
 	}
 
 	if ((new_w > 1) && (new_h > 1)) {
-		if (pixbuf_task->dest != NULL)
-			g_object_unref (pixbuf_task->dest);
+		_g_object_unref (pixbuf_task->dest);
 		pixbuf_task->dest = _gdk_pixbuf_scale_simple_safe (pixbuf_task->src, new_w, new_h, GDK_INTERP_BILINEAR);
 	}
 	else
diff --git a/gthumb/gth-pixbuf-list-task.c b/gthumb/gth-pixbuf-list-task.c
index 451ff83..a005c3e 100644
--- a/gthumb/gth-pixbuf-list-task.c
+++ b/gthumb/gth-pixbuf-list-task.c
@@ -413,6 +413,7 @@ process_current_file (GthPixbufListTask *self)
 
 	_g_object_unref (self->priv->original_pixbuf);
 	self->priv->original_pixbuf = NULL;
+
 	_g_object_unref (self->priv->new_pixbuf);
 	self->priv->new_pixbuf = NULL;
 
diff --git a/gthumb/pixbuf-io.c b/gthumb/pixbuf-io.c
index d49a2fd..032b056 100644
--- a/gthumb/pixbuf-io.c
+++ b/gthumb/pixbuf-io.c
@@ -163,6 +163,7 @@ _gdk_pixbuf_save_async (GdkPixbuf        *pixbuf,
 	GError         *error = NULL;
 	void           *buffer;
 	gsize           buffer_size;
+	GdkPixbuf      *tmp_pixbuf;
 	SavePixbufData *data;
 
 	saver = gth_main_get_pixbuf_saver (mime_type);
@@ -172,20 +173,22 @@ _gdk_pixbuf_save_async (GdkPixbuf        *pixbuf,
 		return;
 	}
 
+	tmp_pixbuf = gdk_pixbuf_copy (pixbuf);
 	if (! gth_pixbuf_saver_save_pixbuf (saver,
-					    pixbuf,
+					    tmp_pixbuf,
 					    (char **)&buffer,
 					    &buffer_size,
 					    mime_type,
 					    &error))
 	{
+		g_object_unref (tmp_pixbuf);
 		gth_file_data_ready_with_error (file_data, ready_func, ready_data, error);
 		return;
 	}
 
 	data = g_new0 (SavePixbufData, 1);
 	data->file_data = g_object_ref (file_data);
-	data->pixbuf = g_object_ref (pixbuf);
+	data->pixbuf = tmp_pixbuf;
 	data->mime_type = mime_type;
 	data->replace = replace;
 	data->buffer = buffer;
@@ -204,6 +207,7 @@ _gdk_pixbuf_save_async (GdkPixbuf        *pixbuf,
 		data->files = g_list_prepend (data->files, file);
 	}
 	else {
+		save_pixbuf_data_free (data);
 		g_free (buffer);
 		gth_file_data_ready_with_error (file_data, ready_func, ready_data, error);
 		return;



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