diff --git a/src/dbus.c b/src/dbus.c index 5b13ccf..2688efa 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 fb0bb8d..68c025d 100644 --- a/src/notification.c +++ b/src/notification.c @@ -163,6 +163,33 @@ 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 + */ +void rawimage_free(RawImage *i) +{ + if (!i) + return; + + g_free(i->data); + g_free(i); +} + /* * Free the memory used by the given notification. */ @@ -179,16 +206,8 @@ 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); - } - - if (n->raw_icon) { - if (n->raw_icon->data) - g_free(n->raw_icon->data); - g_free(n->raw_icon); - } + actions_free(n->actions); + rawimage_free(n->raw_icon); g_free(n); } diff --git a/src/notification.h b/src/notification.h index b45f9fb..d5b0ae9 100644 --- a/src/notification.h +++ b/src/notification.h @@ -33,7 +33,6 @@ typedef struct _notification { char *appname; char *summary; char *body; - bool icon_overridden; char *icon; RawImage *raw_icon; char *msg; /* formatted message */ @@ -63,6 +62,8 @@ 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); int notification_cmp_data(const void *a, const void *b, void *data); diff --git a/src/rules.c b/src/rules.c index fa30c7c..a9455b2 100644 --- a/src/rules.c +++ b/src/rules.c @@ -25,7 +25,8 @@ void rule_apply(rule_t *r, notification *n) if (r->new_icon) { g_free(n->icon); n->icon = g_strdup(r->new_icon); - n->icon_overridden = true; + rawimage_free(n->raw_icon); + n->raw_icon = NULL; } if (r->fg) n->color_strings[ColFG] = r->fg; diff --git a/src/x11/x.c b/src/x11/x.c index 3647222..0710b67 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -425,7 +425,7 @@ static colored_layout *r_init_shared(cairo_t *c, notification *n) GdkPixbuf *pixbuf = NULL; - if (n->raw_icon && !n->icon_overridden && + if (n->raw_icon && settings.icon_position != icons_off) { pixbuf = get_pixbuf_from_raw_image(n->raw_icon);