From 13ed6301d86af984364fce86640a9d23f6f0fb66 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 29 Oct 2017 13:40:43 +0100 Subject: [PATCH] Add separate function to free RawImage --- src/notification.c | 19 ++++++++++++++----- src/notification.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/notification.c b/src/notification.c index 145e0c4..45e151d 100644 --- a/src/notification.c +++ b/src/notification.c @@ -163,6 +163,19 @@ int notification_is_duplicate(const notification *a, const notification *b) && a->urgency == b->urgency; } +/* + * Free a #RawImage + * @i: (nullable): pointer to #RawImage + */ +void rawimage_free(RawImage *i) +{ + if (!i) + return; + + g_free(i->data); + g_free(i); +} + /* * Free the memory used by the given notification. */ @@ -184,11 +197,7 @@ void notification_free(notification *n) g_free(n->actions->dmenu_str); } - if (n->raw_icon) { - if (n->raw_icon->data) - g_free(n->raw_icon->data); - g_free(n->raw_icon); - } + rawimage_free(n->raw_icon); g_free(n); } diff --git a/src/notification.h b/src/notification.h index e5250c1..fa3effa 100644 --- a/src/notification.h +++ b/src/notification.h @@ -63,6 +63,7 @@ typedef struct _notification { notification *notification_create(void); void notification_init(notification *n); +void rawimage_free(RawImage *i); void notification_free(notification *n); int notification_cmp(const void *a, const void *b); int notification_cmp_data(const void *a, const void *b, void *data);