From 4fe05fe39a772d3c45149a66c014f923c6e29b23 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Sat, 17 Aug 2024 23:25:10 +0200 Subject: [PATCH] Fix double free --- src/notification.c | 1 - src/rules.c | 5 +++++ test/dbus.c | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/notification.c b/src/notification.c index d27627470..39feaea0a 100644 --- a/src/notification.c +++ b/src/notification.c @@ -458,7 +458,6 @@ struct notification *notification_create(void) n->colors.fg = invalid; n->colors.bg = invalid; n->colors.frame = invalid; - n->colors.highlight = NULL; n->script_run = false; diff --git a/src/rules.c b/src/rules.c index 83724c29a..63b1b154b 100644 --- a/src/rules.c +++ b/src/rules.c @@ -241,6 +241,11 @@ void rule_free(struct rule *r) g_free(r->set_stack_tag); g_free(r->new_icon); g_free(r->name); + + // Ugly but necessary + if (r->highlight != settings.colors_low.highlight && + r->highlight != settings.colors_norm.highlight && + r->highlight != settings.colors_crit.highlight) gradient_free(r->highlight); } diff --git a/test/dbus.c b/test/dbus.c index 2c68ff955..77d7d42bb 100644 --- a/test/dbus.c +++ b/test/dbus.c @@ -760,7 +760,12 @@ TEST test_dbus_notify_colors(void) // Invalid color strings are ignored ASSERTm("Invalid color strings should not change the color struct", COLOR_SAME(n->colors.bg, settings.colors_norm.bg)); - ASSERTm("Invalid color strings should not change the gradient struct", n->colors.highlight == settings.colors_norm.highlight); + + ASSERTm("Invalid color strings should not change the gradient struct", n->colors.highlight->length == settings.colors_norm.highlight->length); + + for (int i = 0; i < settings.colors_norm.highlight->length; i++) + ASSERTm("Invalid color strings should not change the gradient struct", + COLOR_SAME(n->colors.highlight->colors[i], settings.colors_norm.highlight->colors[i])); dbus_notification_free(n_dbus);