[gdk-pixbuf/gdk-pixbuf-2-38] xpm: Simplify error path



commit 8e23cc9a31ba1f869415e764e2b463dbaeac2e8a
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Mar 1 12:18:06 2019 +0100

    xpm: Simplify error path

 gdk-pixbuf/io-xpm.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/gdk-pixbuf/io-xpm.c b/gdk-pixbuf/io-xpm.c
index 0da5b241b..8a4ceee71 100644
--- a/gdk-pixbuf/io-xpm.c
+++ b/gdk-pixbuf/io-xpm.c
@@ -459,7 +459,7 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
        GHashTable *color_hash;
        XPMColor *colors, *color, *fallbackcolor;
        guchar *pixtmp;
-       GdkPixbuf *pixbuf;
+       GdkPixbuf *pixbuf = NULL;
        gint rowstride;
 
        fallbackcolor = NULL;
@@ -556,10 +556,7 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
                                              GDK_PIXBUF_ERROR,
                                              GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
                                              _("Cannot read XPM colormap"));
-                       g_hash_table_destroy (color_hash);
-                       g_free (name_buf);
-                       g_free (colors);
-                       return NULL;
+                        goto out;
                }
 
                color = &colors[cnt];
@@ -594,10 +591,7 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
                                      GDK_PIXBUF_ERROR,
                                      GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
                                      _("Cannot allocate memory for loading XPM image"));
-               g_hash_table_destroy (color_hash);
-               g_free (colors);
-               g_free (name_buf);
-               return NULL;
+                goto out;
        }
 
        rowstride = gdk_pixbuf_get_rowstride (pixbuf);
@@ -646,6 +640,14 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
        }
 
        return pixbuf;
+
+out:
+       g_hash_table_destroy (color_hash);
+       g_free (colors);
+       g_free (name_buf);
+
+       g_clear_object (&pixbuf);
+       return NULL;
 }
 
 /* Shared library entry point for file loading */


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