[gimp] app: implement error handling in gimp_imagefile_icon_callback()



commit dd0042f76bb7fd941a70c9d85968d9c2523cdedc
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jun 19 23:31:29 2011 +0200

    app: implement error handling in gimp_imagefile_icon_callback()
    
    Particularly, don't crash if the async operation got cancelled in
    dispose().

 app/core/gimpimagefile.c |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/app/core/gimpimagefile.c b/app/core/gimpimagefile.c
index 47d2d1e..aa2aa37 100644
--- a/app/core/gimpimagefile.c
+++ b/app/core/gimpimagefile.c
@@ -626,22 +626,41 @@ gimp_imagefile_icon_callback (GObject      *source_object,
                               GAsyncResult *result,
                               gpointer      data)
 {
-  GimpImagefile        *imagefile = GIMP_IMAGEFILE (data);
-  GimpImagefilePrivate *private   = GET_PRIVATE (imagefile);
-  GFile                *file      = G_FILE (source_object);
-  GError               *error     = NULL;
+  GimpImagefile        *imagefile;
+  GimpImagefilePrivate *private;
+  GFile                *file  = G_FILE (source_object);
+  GError               *error = NULL;
   GFileInfo            *file_info;
 
   file_info = g_file_query_info_finish (file, result, &error);
 
+  if (error)
+    {
+      /* we were cancelled from dispose() and the imagefile is
+       * long gone, bail out
+       */
+      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        {
+          g_clear_error (&error);
+          return;
+        }
+
+#ifdef GIMP_UNSTABLE
+      g_printerr ("%s: %s\n", G_STRFUNC, error->message);
+#endif
+
+      g_clear_error (&error);
+    }
+
+  imagefile = GIMP_IMAGEFILE (data);
+  private   = GET_PRIVATE (imagefile);
+
   if (file_info)
     {
       private->icon = g_object_ref (g_file_info_get_icon (file_info));
       g_object_unref (file_info);
     }
 
-  g_clear_error (&error);
-
   if (private->icon_cancellable)
     {
       g_object_unref (private->icon_cancellable);



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