From 34fd1234a6b901c1e82dc8aecd88f48ea9018327 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 18 Nov 2013 11:05:39 +0000 Subject: [PATCH] pixbuf-engine: Clean up error conditions and destructors Simplify the error checks and move all common behaviour into a utility function. https://bugzilla.gnome.org/show_bug.cgi?id=712536 --- modules/engines/pixbuf/pixbuf-rc-style.c | 59 +++++++++--------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/modules/engines/pixbuf/pixbuf-rc-style.c b/modules/engines/pixbuf/pixbuf-rc-style.c index 1d7972ac5e..57cb3b31e5 100644 --- a/modules/engines/pixbuf/pixbuf-rc-style.c +++ b/modules/engines/pixbuf/pixbuf-rc-style.c @@ -619,20 +619,24 @@ theme_image_unref (ThemeImage *data) if (data->refcount == 0) { g_free (data->match_data.detail); - if (data->background) - theme_pixbuf_destroy (data->background); - if (data->overlay) - theme_pixbuf_destroy (data->overlay); - if (data->gap_start) - theme_pixbuf_destroy (data->gap_start); - if (data->gap) - theme_pixbuf_destroy (data->gap); - if (data->gap_end) - theme_pixbuf_destroy (data->gap_end); + theme_pixbuf_destroy (data->background); + theme_pixbuf_destroy (data->overlay); + theme_pixbuf_destroy (data->gap_start); + theme_pixbuf_destroy (data->gap_end); + theme_pixbuf_destroy (data->gap); g_free (data); } } +static inline void +clear_theme_pixbuf_and_warn (ThemePixbuf **theme_pb, + GScanner *scanner, + const char *message) +{ + theme_clear_pixbuf (theme_pb); + g_scanner_warn (scanner, message); +} + static guint theme_parse_image(GtkSettings *settings, GScanner *scanner, @@ -756,38 +760,21 @@ theme_parse_image(GtkSettings *settings, token = g_scanner_get_next_token(scanner); if (data->background && !data->background->filename) - { - g_scanner_warn (scanner, "Background image options specified without filename"); - theme_pixbuf_destroy (data->background); - data->background = NULL; - } + clear_theme_pixbuf_and_warn (&data->background, scanner, "Background image options specified without filename"); if (data->overlay && !data->overlay->filename) - { - g_scanner_warn (scanner, "Overlay image options specified without filename"); - theme_pixbuf_destroy (data->overlay); - data->overlay = NULL; - } + clear_theme_pixbuf_and_warn (&data->overlay, scanner, "Overlay image options specified without filename"); - if (data->gap && !data->gap->filename) + if (!data->gap->filename) { - g_scanner_warn (scanner, "Gap image options specified without filename"); - theme_pixbuf_destroy (data->gap); - data->gap = NULL; - } + if (data->gap) + clear_theme_pixbuf_and_warn (&data->gap, scanner, "Gap image options specified without filename"); - if (data->gap_start && !data->gap_start->filename) - { - g_scanner_warn (scanner, "Gap start image options specified without filename"); - theme_pixbuf_destroy (data->gap_start); - data->gap_start = NULL; - } + if (data->gap_start) + clear_theme_pixbuf_and_warn (&data->gap_start, scanner, "Gap start image options specified without filename"); - if (data->gap_end && !data->gap_end->filename) - { - g_scanner_warn (scanner, "Gap end image options specified without filename"); - theme_pixbuf_destroy (data->gap_end); - data->gap_end = NULL; + if (data->gap_end) + clear_theme_pixbuf_and_warn (&data->gap_end, scanner, "Gap end image options specified without filename"); } if (token != G_TOKEN_RIGHT_CURLY)