[gthumb] check whether the scaled surface is null before using it



commit 3c36904e597fbd60970aacb8b35e7864757a48f0
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Dec 16 20:41:34 2019 +0100

    check whether the scaled surface is null before using it

 extensions/facebook/facebook-service.c       |  6 ++--
 extensions/file_tools/gth-file-tool-resize.c |  8 ++++--
 extensions/resize_images/dlg-resize-images.c |  5 +---
 extensions/webalbums/gth-web-exporter.c      | 42 ++++++++++++++++------------
 gthumb/gth-image-overview.c                  |  5 +---
 gthumb/gth-image-utils.c                     |  7 +++++
 gthumb/gth-thumb-loader.c                    |  3 +-
 7 files changed, 44 insertions(+), 32 deletions(-)
---
diff --git a/extensions/facebook/facebook-service.c b/extensions/facebook/facebook-service.c
index b5df7b94..7a99f802 100644
--- a/extensions/facebook/facebook-service.c
+++ b/extensions/facebook/facebook-service.c
@@ -831,8 +831,10 @@ upload_photo_file_buffer_ready_cb (void     **buffer,
                        cairo_surface_t *scaled;
 
                        scaled = _cairo_image_surface_scale (surface, width, height, SCALE_FILTER_BEST, NULL);
-                       cairo_surface_destroy (surface);
-                       surface = scaled;
+                       if (scaled != NULL) {
+                               cairo_surface_destroy (surface);
+                               surface = scaled;
+                       }
                }
 
                g_free (*buffer);
diff --git a/extensions/file_tools/gth-file-tool-resize.c b/extensions/file_tools/gth-file-tool-resize.c
index b7478ebd..9ed479be 100644
--- a/extensions/file_tools/gth-file-tool-resize.c
+++ b/extensions/file_tools/gth-file-tool-resize.c
@@ -158,10 +158,12 @@ resize_task_exec (GthAsyncTask *task,
                                                  self->priv->new_height,
                                                  (self->priv->high_quality ? SCALE_FILTER_BEST : 
SCALE_FILTER_FAST),
                                                  task);
-       _cairo_image_surface_clear_metadata (destination);
-       gth_image_task_set_destination_surface (GTH_IMAGE_TASK (task), destination);
+       if (destination != NULL) {
+               _cairo_image_surface_clear_metadata (destination);
+               gth_image_task_set_destination_surface (GTH_IMAGE_TASK (task), destination);
+               cairo_surface_destroy (destination);
+       }
 
-       cairo_surface_destroy (destination);
        cairo_surface_destroy (source);
 
        return NULL;
diff --git a/extensions/resize_images/dlg-resize-images.c b/extensions/resize_images/dlg-resize-images.c
index a0a737b4..47dd4bef 100644
--- a/extensions/resize_images/dlg-resize-images.c
+++ b/extensions/resize_images/dlg-resize-images.c
@@ -126,10 +126,7 @@ exec_resize (GthAsyncTask *task,
                new_h = max_h;
        }
 
-       if ((new_w > 1) && (new_h > 1))
-               destination = _cairo_image_surface_scale (source, new_w, new_h, SCALE_FILTER_BEST, task);
-       else
-               destination = NULL;
+       destination = _cairo_image_surface_scale (source, new_w, new_h, SCALE_FILTER_BEST, task);
        destination_image = gth_image_new_for_surface (destination);
        gth_image_task_set_destination (GTH_IMAGE_TASK (task), destination_image);
 
diff --git a/extensions/webalbums/gth-web-exporter.c b/extensions/webalbums/gth-web-exporter.c
index a6cd5f20..96c654c3 100644
--- a/extensions/webalbums/gth-web-exporter.c
+++ b/extensions/webalbums/gth-web-exporter.c
@@ -2584,14 +2584,16 @@ image_loader_ready_cb (GObject      *source_object,
                {
                        cairo_surface_t *scaled;
 
-                       g_object_ref (idata->image);
-
                        scaled = _cairo_image_surface_scale (surface, w, h, SCALE_FILTER_BEST, NULL);
-                       idata->image = gth_image_new_for_surface (scaled);
-                       idata->image_width = cairo_image_surface_get_width (scaled);
-                       idata->image_height = cairo_image_surface_get_height (scaled);
+                       if (scaled != NULL) {
+                               g_object_unref (idata->image);
 
-                       cairo_surface_destroy (scaled);
+                               idata->image = gth_image_new_for_surface (scaled);
+                               idata->image_width = cairo_image_surface_get_width (scaled);
+                               idata->image_height = cairo_image_surface_get_height (scaled);
+
+                               cairo_surface_destroy (scaled);
+                       }
                }
        }
 
@@ -2614,14 +2616,16 @@ image_loader_ready_cb (GObject      *source_object,
                {
                        cairo_surface_t *scaled;
 
-                       g_object_ref (idata->preview);
-
                        scaled = _cairo_image_surface_scale (surface, w, h, SCALE_FILTER_BEST, NULL);
-                       idata->preview = gth_image_new_for_surface (scaled);
-                       idata->preview_width = cairo_image_surface_get_width (scaled);
-                       idata->preview_height = cairo_image_surface_get_height (scaled);
+                       if (scaled != NULL) {
+                               g_object_unref (idata->preview);
 
-                       cairo_surface_destroy (scaled);
+                               idata->preview = gth_image_new_for_surface (scaled);
+                               idata->preview_width = cairo_image_surface_get_width (scaled);
+                               idata->preview_height = cairo_image_surface_get_height (scaled);
+
+                               cairo_surface_destroy (scaled);
+                       }
                }
        }
 
@@ -2662,14 +2666,16 @@ image_loader_ready_cb (GObject      *source_object,
                {
                        cairo_surface_t *scaled;
 
-                       g_object_unref (idata->thumb);
-
                        scaled = _cairo_image_surface_scale (surface, w, h, SCALE_FILTER_BEST, NULL);
-                       idata->thumb = gth_image_new_for_surface (scaled);
-                       idata->thumb_width = cairo_image_surface_get_width (scaled);
-                       idata->thumb_height = cairo_image_surface_get_height (scaled);
+                       if (scaled != NULL) {
+                               g_object_unref (idata->thumb);
 
-                       cairo_surface_destroy (scaled);
+                               idata->thumb = gth_image_new_for_surface (scaled);
+                               idata->thumb_width = cairo_image_surface_get_width (scaled);
+                               idata->thumb_height = cairo_image_surface_get_height (scaled);
+
+                               cairo_surface_destroy (scaled);
+                       }
                }
        }
 
diff --git a/gthumb/gth-image-overview.c b/gthumb/gth-image-overview.c
index 11f86748..def0a2c8 100644
--- a/gthumb/gth-image-overview.c
+++ b/gthumb/gth-image-overview.c
@@ -261,11 +261,8 @@ _gth_image_overview_scale_after (GthAsyncTask *task,
                if (overview->priv->viewer != NULL) {
                        _gth_image_overview_update_zoom_info (overview);
                        _cairo_clear_surface (&overview->priv->preview);
-                       if (scale_data->scaled != NULL) {
-                               if (overview->priv->preview != NULL)
-                                       cairo_surface_destroy (overview->priv->preview);
+                       if (scale_data->scaled != NULL)
                                overview->priv->preview = cairo_surface_reference (scale_data->scaled);
-                       }
                        gtk_widget_queue_resize (GTK_WIDGET (overview));
                }
 
diff --git a/gthumb/gth-image-utils.c b/gthumb/gth-image-utils.c
index 207b45b1..a4612ffc 100644
--- a/gthumb/gth-image-utils.c
+++ b/gthumb/gth-image-utils.c
@@ -148,6 +148,13 @@ _g_buffer_resize_image (void          *buffer,
 
        surface = gth_image_get_cairo_surface (image);
        scaled = _cairo_image_surface_scale (surface, width, height, SCALE_FILTER_BEST, NULL);
+       if (scaled == NULL) {
+               cairo_surface_destroy (surface);
+               g_object_unref (image);
+               g_object_unref (istream);
+               return FALSE;
+       }
+
        gth_image_set_cairo_surface (image, scaled);
        result = gth_image_save_to_buffer (image,
                                           mime_type,
diff --git a/gthumb/gth-thumb-loader.c b/gthumb/gth-thumb-loader.c
index f04a63f4..c9c0a9a0 100644
--- a/gthumb/gth-thumb-loader.c
+++ b/gthumb/gth-thumb-loader.c
@@ -428,7 +428,8 @@ _cairo_image_surface_scale_for_thumbnail (cairo_surface_t *image,
        cairo_surface_t *scaled;
 
        scaled = _cairo_image_surface_scale (image, new_width, new_height, SCALE_FILTER_GOOD, NULL);
-       _cairo_image_surface_copy_metadata (image, scaled);
+       if (scaled != NULL)
+               _cairo_image_surface_copy_metadata (image, scaled);
 
        return scaled;
 }


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