[gdk-pixbuf] animation: Improve error handling



commit 9201fcfdcafd865bc10624c5c3a12192b5eeea9a
Author: Benjamin Otte <otte redhat com>
Date:   Tue Feb 19 14:16:20 2013 +0100

    animation: Improve error handling
    
    The previous code couldn't guarantee that an animation existed when there
    wasn't an error not could it guarantee that no animation was returned
    when there indeed was an error.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694148

 gdk-pixbuf/gdk-pixbuf-animation.c |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c
index 38d30f5..e39a592 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.c
+++ b/gdk-pixbuf/gdk-pixbuf-animation.c
@@ -218,39 +218,41 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
                 guchar buffer[4096];
                 size_t length;
                 gpointer context;
+                gboolean success;
 
+                success = FALSE;
                 animation = NULL;
                fseek (f, 0, SEEK_SET);
 
                 context = image_module->begin_load (NULL, prepared_notify, NULL, &animation, error);
-                
-                if (!context) {
-                        error = NULL;
-                        goto fail_progressive_load;
-                }
+                if (!context)
+                        goto fail_begin_load;
                 
                 while (!feof (f) && !ferror (f)) {
                         length = fread (buffer, 1, sizeof (buffer), f);
                         if (length > 0) {
                                 if (!image_module->load_increment (context, buffer, length, error)) {
                                         error = NULL;
-                                        goto fail_progressive_load;
+                                        goto fail_load_increment;
                                 }
                         }
                 }
 
-fail_progressive_load:
+                /* If there was no error, there must be an animation that was successfully loaded */
+                g_assert (animation);
+                success = TRUE;
+
+fail_load_increment:
+                if (!image_module->stop_load (context, error))
+                        success = FALSE;
+
+fail_begin_load:
                fclose (f);
 
-                if (context && !image_module->stop_load (context, error)) {
-                        if (animation)
-                                g_object_unref (animation);
-                        g_free (display_name);
-                        return NULL;
+                if (!success && animation) {
+                        g_object_unref (animation);
+                        animation = NULL;
                 }
-
-                /* If there was no error, there must be an animation that was successfully loaded */
-                g_assert (animation);
        } else {
                GdkPixbuf *pixbuf;
 


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