summaryrefslogtreecommitdiff
path: root/modules/engines/pixbuf
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2013-11-18 11:04:37 +0000
committerMatthias Clasen <mclasen@redhat.com>2013-11-22 22:17:07 -0500
commit01dfd8bb6e80c5e23cd94559244b3ea402ad0e62 (patch)
tree49658df1bc5a6cee4ebcbf19a9668b5a9df3c5cc /modules/engines/pixbuf
parent0d396abf22f09ae36fa89aa109589a1a726079d7 (diff)
downloadgtk+-01dfd8bb6e80c5e23cd94559244b3ea402ad0e62.tar.gz
pixbuf-engine: Improve ThemePixbuf clean up functions
Make theme_pixbuf_destroy() NULL-safe like g_free(), and add a clear function in the spirit of the g_clear_* family of functions. https://bugzilla.gnome.org/show_bug.cgi?id=712536
Diffstat (limited to 'modules/engines/pixbuf')
-rw-r--r--modules/engines/pixbuf/pixbuf-render.c21
-rw-r--r--modules/engines/pixbuf/pixbuf.h1
2 files changed, 20 insertions, 2 deletions
diff --git a/modules/engines/pixbuf/pixbuf-render.c b/modules/engines/pixbuf/pixbuf-render.c
index 6fb93bc495..1b2fd991c8 100644
--- a/modules/engines/pixbuf/pixbuf-render.c
+++ b/modules/engines/pixbuf/pixbuf-render.c
@@ -492,8 +492,25 @@ theme_pixbuf_new (void)
void
theme_pixbuf_destroy (ThemePixbuf *theme_pb)
{
- theme_pixbuf_set_filename (theme_pb, NULL);
- g_free (theme_pb);
+ if (G_LIKELY (theme_pb))
+ {
+ theme_pixbuf_set_filename (theme_pb, NULL);
+ g_free (theme_pb);
+ }
+}
+
+void
+theme_clear_pixbuf (ThemePixbuf **theme_pb)
+{
+#if GLIB_CHECK_VERSION (2, 34, 0)
+ g_clear_pointer (theme_pb, theme_pixbuf_destroy);
+#else
+ if (*theme_pb)
+ {
+ theme_pixbuf_destroy (*theme_pb);
+ *theme_pb = NULL;
+ }
+#endif
}
void
diff --git a/modules/engines/pixbuf/pixbuf.h b/modules/engines/pixbuf/pixbuf.h
index c844421f38..03cbac9a57 100644
--- a/modules/engines/pixbuf/pixbuf.h
+++ b/modules/engines/pixbuf/pixbuf.h
@@ -188,6 +188,7 @@ struct _ThemeImage
G_GNUC_INTERNAL ThemePixbuf *theme_pixbuf_new (void);
G_GNUC_INTERNAL void theme_pixbuf_destroy (ThemePixbuf *theme_pb);
+G_GNUC_INTERNAL void theme_clear_pixbuf (ThemePixbuf **theme_pb);
G_GNUC_INTERNAL void theme_pixbuf_set_filename (ThemePixbuf *theme_pb,
const char *filename);
G_GNUC_INTERNAL GdkPixbuf * theme_pixbuf_get_pixbuf (ThemePixbuf *theme_pb);