From b571698f522192a62eae7e64f1b9f54844e97e81 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 29 Oct 2017 16:17:50 +0100 Subject: [PATCH] Free Actions in separate method Also free the memory of the actual Action. --- src/dbus.c | 11 +++++------ src/notification.c | 20 +++++++++++++++----- src/notification.h | 1 + 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index b669b70..01ac877 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -267,13 +267,12 @@ static void on_notify(GDBusConnection *connection, n->category = category; n->dbus_client = g_strdup(sender); n->transient = transient; - if (actions->count > 0) { - n->actions = actions; - } else { - n->actions = NULL; - g_strfreev(actions->actions); - g_free(actions); + + if (actions->count < 1) { + actions_free(actions); + actions = NULL; } + n->actions = actions; for (int i = 0; i < ColLast; i++) { n->color_strings[i] = NULL; diff --git a/src/notification.c b/src/notification.c index 45e151d..5b71ebb 100644 --- a/src/notification.c +++ b/src/notification.c @@ -163,6 +163,20 @@ int notification_is_duplicate(const notification *a, const notification *b) && a->urgency == b->urgency; } +/* + * Free the actions element + * @a: (nullable): Pointer to #Actions + */ +void actions_free(Actions *a) +{ + if (!a) + return; + + g_strfreev(a->actions); + g_free(a->dmenu_str); + g_free(a); +} + /* * Free a #RawImage * @i: (nullable): pointer to #RawImage @@ -192,11 +206,7 @@ void notification_free(notification *n) g_free(n->text_to_render); g_free(n->urls); - if (n->actions) { - g_strfreev(n->actions->actions); - g_free(n->actions->dmenu_str); - } - + actions_free(n->actions); rawimage_free(n->raw_icon); g_free(n); diff --git a/src/notification.h b/src/notification.h index d02f929..676548d 100644 --- a/src/notification.h +++ b/src/notification.h @@ -62,6 +62,7 @@ typedef struct _notification { notification *notification_create(void); void notification_init(notification *n); +void actions_free(Actions *a); void rawimage_free(RawImage *i); void notification_free(notification *n); int notification_cmp(const void *a, const void *b);