[gthumb] Quitting slideshow sometimes causes Segmentation fault



commit a2bd99167b284a24d9e32fabf6609e9904bd1d77
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Jan 26 10:16:11 2012 +0100

    Quitting slideshow sometimes causes Segmentation fault
    
    Based on a Greg Mansfield's patch
    
    [bug #668672]

 gthumb/gth-image-preloader.c |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/gthumb/gth-image-preloader.c b/gthumb/gth-image-preloader.c
index 8132dc8..e63af67 100644
--- a/gthumb/gth-image-preloader.c
+++ b/gthumb/gth-image-preloader.c
@@ -43,11 +43,13 @@ enum {
 
 
 typedef struct {
+	int                 ref;
 	GthImagePreloader  *self;
 	GthFileData        *file_data;
 	int                 requested_size;
 	gboolean            loaded;
 	gboolean            error;
+	gboolean	    canceled;
 	GthImageLoader     *loader;
 	GthImage           *image;
 	int                 original_width;
@@ -96,10 +98,12 @@ preloader_new (GthImagePreloader *self)
 	Preloader *preloader;
 
 	preloader = g_new0 (Preloader, 1);
+	preloader->ref = 1;
 	preloader->self = self;
 	preloader->file_data = NULL;
 	preloader->loaded = FALSE;
 	preloader->error = FALSE;
+	preloader->canceled = FALSE;
 	preloader->loader = gth_image_loader_new (NULL, NULL);
 	gth_image_loader_set_preferred_format (preloader->loader, GTH_IMAGE_FORMAT_CAIRO_SURFACE);
 	preloader->image = NULL;
@@ -110,11 +114,21 @@ preloader_new (GthImagePreloader *self)
 }
 
 
+static Preloader *
+preloader_ref (Preloader *preloader)
+{
+	preloader->ref++;
+	return preloader;
+}
+
+
 static void
-preloader_free (Preloader *preloader)
+preloader_unref (Preloader *preloader)
 {
 	if (preloader == NULL)
 		return;
+	if (--preloader->ref > 0)
+		return;
 	_g_object_unref (preloader->image);
 	_g_object_unref (preloader->loader);
 	_g_object_unref (preloader->file_data);
@@ -221,7 +235,8 @@ gth_image_preloader_finalize (GObject *object)
 	}
 
 	for (i = 0; i < self->priv->n_preloaders; i++) {
-		preloader_free (self->priv->loader[i]);
+		self->priv->loader[i]->canceled = TRUE;
+		preloader_unref (self->priv->loader[i]);
 		self->priv->loader[i] = NULL;
 	}
 	g_free (self->priv->loader);
@@ -354,6 +369,7 @@ typedef struct {
 static void
 load_request_free (LoadRequest *load_request)
 {
+	preloader_unref (load_request->preloader);
 	g_object_unref (load_request->file_data);
 	g_free (load_request);
 }
@@ -374,6 +390,11 @@ image_loader_ready_cb (GObject      *source_object,
 	gboolean            success;
 	int                 interval;
 
+	if (preloader->canceled) {
+		load_request_free (load_request);
+		return;
+	}
+
 	self->priv->current = -1;
 
 	success = gth_image_loader_load_finish  (GTH_IMAGE_LOADER (source_object),
@@ -501,7 +522,7 @@ start_next_loader (GthImagePreloader *self)
 		preloader->image = NULL;
 
 		load_request = g_new0 (LoadRequest, 1);
-		load_request->preloader = preloader;
+		load_request->preloader = preloader_ref (preloader);
 		load_request->file_data = g_object_ref (preloader->file_data);
 		load_request->requested_size = preloader->requested_size;
 



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