From 1b37ab503d6955cee23ecaaf633558ae7d24afdb Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:16:18 +0100 Subject: [PATCH 1/4] Fix gradient ownership in rule --- src/dunst.c | 1 + src/option_parser.c | 13 +++++++++++-- src/rules.c | 7 ++----- src/rules.h | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/dunst.c b/src/dunst.c index cf076aad4..8115b4ad2 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -223,6 +223,7 @@ void reload(char **const configs) setup_done = false; draw_deinit(); + settings_free(&settings); load_settings(configs); draw_setup(); setup_done = true; diff --git a/src/option_parser.c b/src/option_parser.c index 92f6dd62f..1c03a561d 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -457,7 +457,17 @@ int set_rule_value(struct rule* r, struct setting setting, char* value) { // guaranteed to be 1 byte void *target = (char*)r + setting.rule_offset; - return set_from_string(target, setting, value); + if (!set_from_string(target, setting, value)) + return false; + + if (STR_EQ(setting.name, "highlight")) { + // Check ownership for freeing it later + r->highlight_owned = r->highlight != settings.colors_low.highlight + && r->highlight != settings.colors_norm.highlight + && r->highlight != settings.colors_crit.highlight; + } + + return true; } bool set_rule(struct setting setting, char* value, char* section) { @@ -466,7 +476,6 @@ bool set_rule(struct setting setting, char* value, char* section) { r = rule_new(section); LOG_D("Creating new rule '%s'", section); } - return set_rule_value(r, setting, value); } diff --git a/src/rules.c b/src/rules.c index 63b1b154b..ef221094b 100644 --- a/src/rules.c +++ b/src/rules.c @@ -242,11 +242,8 @@ void rule_free(struct rule *r) 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); + if (r->highlight_owned) + gradient_free(r->highlight); } diff --git a/src/rules.h b/src/rules.h index dc205f7ea..dae9b5ada 100644 --- a/src/rules.h +++ b/src/rules.h @@ -51,6 +51,7 @@ struct rule { struct color fg; struct color bg; struct gradient *highlight; + bool highlight_owned; struct color fc; char *set_category; const char *format; From cd715745373528498ec4d2fb7deeb69e160aae82 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Tue, 10 Dec 2024 18:02:38 +0100 Subject: [PATCH 2/4] Properly free settigs and rc gradients --- src/dbus.c | 10 ++++---- src/draw.c | 28 +++++++++++++++------- src/draw.h | 4 +++- src/dunst.c | 9 ++++--- src/notification.c | 40 ++++++++++++++++++++----------- src/notification.h | 4 +++- src/option_parser.c | 18 ++++---------- src/queues.c | 2 +- src/rules.c | 56 ++++++++++++++++++++++++++++++-------------- src/rules.h | 5 ++-- src/settings.c | 45 +++++++++++++++++++++-------------- src/settings.h | 5 ++-- test/helpers.c | 3 +-- test/notification.c | 4 ++-- test/option_parser.c | 6 ++--- 15 files changed, 144 insertions(+), 95 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index 8d8ec23c0..6dfa2ee75 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -873,8 +873,9 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV gradient_pattern(grad); notification_keep_original(n); - if (!GRADIENT_VALID(n->original->highlight)) n->original->highlight = n->colors.highlight; - n->colors.highlight = grad; + if (!GRADIENT_VALID(n->original->highlight)) n->original->highlight = gradient_acquire(n->colors.highlight); + gradient_release(n->colors.highlight); + n->colors.highlight = gradient_acquire(grad); end: g_variant_unref(dict_value); @@ -886,8 +887,9 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV gradient_pattern(grad); notification_keep_original(n); - if (!GRADIENT_VALID(n->original->highlight)) n->original->highlight = n->colors.highlight; - n->colors.highlight = grad; + if (!GRADIENT_VALID(n->original->highlight)) n->original->highlight = gradient_acquire(n->colors.highlight); + gradient_release(n->colors.highlight); + n->colors.highlight = gradient_acquire(grad); } g_variant_unref(dict_value); } diff --git a/src/draw.c b/src/draw.c index 2b0e74053..bfe9841bd 100644 --- a/src/draw.c +++ b/src/draw.c @@ -76,7 +76,7 @@ struct gradient *gradient_alloc(size_t length) if (length == 0) return NULL; - struct gradient *grad = g_malloc(sizeof(struct gradient) + length * sizeof(struct color)); + struct gradient *grad = g_rc_box_alloc(sizeof(struct gradient) + length * sizeof(struct color)); grad->length = length; grad->pattern = NULL; @@ -84,14 +84,21 @@ struct gradient *gradient_alloc(size_t length) return grad; } -void gradient_free(struct gradient *grad) +struct gradient *gradient_acquire(struct gradient *grad) { - if (grad == NULL) return; + return grad != NULL ? g_rc_box_acquire(grad) : NULL; +} +static void gradient_free(struct gradient *grad) +{ if (grad->pattern) cairo_pattern_destroy(grad->pattern); +} - g_free(grad); +void gradient_release(struct gradient *grad) +{ + if (grad != NULL) + g_rc_box_release_full(grad, (GDestroyNotify)gradient_free); } void gradient_pattern(struct gradient *grad) @@ -119,16 +126,19 @@ char *gradient_to_string(const struct gradient *grad) { if (!GRADIENT_VALID(grad)) return NULL; - char *buf = g_malloc(grad->length * 11); - color_to_string(grad->colors[0], buf); - char *ptr = buf + 9; + int max = grad->length * 11 + 1; + char *buf = g_malloc(max); - for (int i = 1; i < grad->length; i++) { - ptr += g_snprintf(ptr, 11, ", #%02x%02x%02x%02x", + for (int i = 0, j = 0; i < grad->length; i++) { + j += g_snprintf(buf + j, max - j, "#%02x%02x%02x%02x", (int)(grad->colors[i].r * 255), (int)(grad->colors[i].g * 255), (int)(grad->colors[i].b * 255), (int)(grad->colors[i].a * 255)); + + if (i != grad->length - 1) { + j += g_snprintf(buf + j, max - j, ", "); + } } return buf; diff --git a/src/draw.h b/src/draw.h index 6821dabee..cac9d4f53 100644 --- a/src/draw.h +++ b/src/draw.h @@ -63,7 +63,9 @@ struct gradient { struct gradient *gradient_alloc(size_t length); -void gradient_free(struct gradient *grad); +struct gradient *gradient_acquire(struct gradient *grad); + +void gradient_release(struct gradient *grad); void gradient_pattern(struct gradient *grad); diff --git a/src/dunst.c b/src/dunst.c index 8115b4ad2..a23de5a68 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -225,6 +225,7 @@ void reload(char **const configs) settings_free(&settings); load_settings(configs); + draw_setup(); setup_done = true; @@ -238,8 +239,6 @@ int dunst_main(int argc, char *argv[]) dunst_status_int(S_PAUSE_LEVEL, 0); dunst_status(S_IDLE, false); - settings_init(); - queues_init(); cmdline_load(argc, argv); @@ -270,9 +269,9 @@ int dunst_main(int argc, char *argv[]) config_paths[count++] = path; } while (path != NULL); - settings.print_notifications = cmdline_get_bool("-print/--print", false, "Print notifications to stdout"); + print_notifications = cmdline_get_bool("-print/--print", false, "Print notifications to stdout"); - settings.startup_notification = cmdline_get_bool("-startup_notification/--startup_notification", + bool startup_notification = cmdline_get_bool("-startup_notification/--startup_notification", false, "Display a notification on startup."); /* Help should always be the last to set up as calls to cmdline_get_* (as a side effect) add entries to the usage list. */ @@ -295,7 +294,7 @@ int dunst_main(int argc, char *argv[]) guint term_src = g_unix_signal_add(SIGTERM, quit_signal, NULL); guint int_src = g_unix_signal_add(SIGINT, quit_signal, NULL); - if (settings.startup_notification) { + if (startup_notification) { struct notification *n = notification_create(); n->id = 0; n->appname = g_strdup("dunst"); diff --git a/src/notification.c b/src/notification.c index 65eb45d21..ce7f86070 100644 --- a/src/notification.c +++ b/src/notification.c @@ -162,7 +162,6 @@ void notification_run_script(struct notification *n) safe_setenv("DUNST_URLS", n->urls); safe_setenv("DUNST_TIMEOUT", n_timeout_str); safe_setenv("DUNST_TIMESTAMP", n_timestamp_str); - safe_setenv("DUNST_STACK_TAG", n->stack_tag); safe_setenv("DUNST_DESKTOP_ENTRY", n->desktop_entry); execlp(script, @@ -303,30 +302,35 @@ void notification_unref(struct notification *n) g_free(n->original); } + g_free(n->dbus_client); g_free(n->appname); g_free(n->summary); g_free(n->body); - g_free(n->iconname); - g_free(n->default_icon_name); - g_free(n->icon_path); - g_free(n->msg); - g_free(n->dbus_client); g_free(n->category); - g_free(n->text_to_render); - g_free(n->urls); - g_free(n->stack_tag); g_free(n->desktop_entry); + g_free(n->icon_id); + g_free(n->iconname); + g_free(n->icon_path); + g_free(n->default_icon_name); + g_hash_table_unref(n->actions); g_free(n->default_action_name); if (n->icon) cairo_surface_destroy(n->icon); - g_free(n->icon_id); notification_private_free(n->priv); + gradient_release(n->colors.highlight); + + g_free(n->format); g_strfreev(n->scripts); + g_free(n->stack_tag); + + g_free(n->msg); + g_free(n->text_to_render); + g_free(n->urls); g_free(n); } @@ -392,6 +396,12 @@ void notification_icon_replace_data(struct notification *n, GVariant *new_icon) g_object_unref(icon); } +void notification_replace_format(struct notification *n, const char *format) +{ + g_free(n->format); + n->format = g_strdup(format); +} + /* see notification.h */ void notification_replace_single_field(char **haystack, char **needle, @@ -434,7 +444,7 @@ struct notification *notification_create(void) /* Unparameterized default values */ n->first_render = true; n->markup = MARKUP_FULL; - n->format = settings.format; + n->format = g_strdup(settings.format); n->timestamp = time_monotonic_now(); @@ -512,7 +522,10 @@ void notification_init(struct notification *n) if (!COLOR_VALID(n->colors.bg)) n->colors.bg = defcolors.bg; if (!COLOR_VALID(n->colors.frame)) n->colors.frame = defcolors.frame; - if (!GRADIENT_VALID(n->colors.highlight)) n->colors.highlight = defcolors.highlight; + if (!GRADIENT_VALID(n->colors.highlight)) { + gradient_release(n->colors.highlight); + n->colors.highlight = gradient_acquire(defcolors.highlight); + } /* Sanitize misc hints */ if (n->progress < 0) @@ -524,7 +537,7 @@ void notification_init(struct notification *n) rule_apply_all(n); if (g_str_has_prefix(n->summary, "DUNST_COMMAND_")) { - char *msg = "DUNST_COMMAND_* has been removed, please switch to dunstctl. See #830 for more details. https://github.com/dunst-project/dunst/pull/830"; + const char *msg = "DUNST_COMMAND_* has been removed, please switch to dunstctl. See #830 for more details. https://github.com/dunst-project/dunst/pull/830"; LOG_W("%s", msg); n->body = string_append(n->body, msg, "\n"); } @@ -538,7 +551,6 @@ void notification_init(struct notification *n) if (!n->icon && !n->iconname) n->iconname = g_strdup(settings.icons[n->urgency]); - /* UPDATE derived fields */ notification_extract_urls(n); notification_format_message(n); diff --git a/src/notification.h b/src/notification.h index e92be74ba..bbec684ed 100644 --- a/src/notification.h +++ b/src/notification.h @@ -85,7 +85,7 @@ struct notification { char *default_action_name; /**< The name of the action to be invoked on do_action */ enum markup_mode markup; - const char *format; + char *format; char **scripts; int script_count; struct notification_colors colors; @@ -202,6 +202,8 @@ void notification_icon_replace_path(struct notification *n, const char *new_icon */ void notification_icon_replace_data(struct notification *n, GVariant *new_icon); +void notification_replace_format(struct notification *n, const char *format); + /** * Run the script associated with the * given notification. diff --git a/src/option_parser.c b/src/option_parser.c index 1c03a561d..09614368f 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -457,17 +457,7 @@ int set_rule_value(struct rule* r, struct setting setting, char* value) { // guaranteed to be 1 byte void *target = (char*)r + setting.rule_offset; - if (!set_from_string(target, setting, value)) - return false; - - if (STR_EQ(setting.name, "highlight")) { - // Check ownership for freeing it later - r->highlight_owned = r->highlight != settings.colors_low.highlight - && r->highlight != settings.colors_norm.highlight - && r->highlight != settings.colors_crit.highlight; - } - - return true; + return set_from_string(target, setting, value); } bool set_rule(struct setting setting, char* value, char* section) { @@ -480,6 +470,9 @@ bool set_rule(struct setting setting, char* value, char* section) { } void set_defaults(void) { + LOG_D("Initializing settings"); + settings = (struct settings) {0}; + for (int i = 0; i < G_N_ELEMENTS(allowed_settings); i++) { // FIXME Rule settings can only have a default if they have an // working entry in the settings struct as well. Make an @@ -698,8 +691,7 @@ void cmdline_usage_append(const char *key, const char *type, const char *descrip } char *tmp; - tmp = - g_strdup_printf("%s%-50s - %s\n", usage_str, key_type, description); + tmp = g_strdup_printf("%s%-50s - %s\n", usage_str, key_type, description); g_free(key_type); g_free(usage_str); diff --git a/src/queues.c b/src/queues.c index 64a218022..ac537e023 100644 --- a/src/queues.c +++ b/src/queues.c @@ -207,7 +207,7 @@ int queues_notification_insert(struct notification *n) notification_icon_replace_path(n, n->iconname); } - if (settings.print_notifications) + if (print_notifications) notification_print(n); return n->id; diff --git a/src/rules.c b/src/rules.c index ef221094b..978fde11d 100644 --- a/src/rules.c +++ b/src/rules.c @@ -60,16 +60,19 @@ void rule_apply(struct rule *r, struct notification *n, bool save) if (save && !COLOR_VALID(n->original->bg)) n->original->bg = n->colors.bg; n->colors.bg = r->bg; } - if (r->highlight) - RULE_APPLY2(colors.highlight, highlight, NULL); + if (r->highlight != NULL) { + if (save && n->original->highlight == NULL) { + n->original->highlight = gradient_acquire(n->colors.highlight); + } + gradient_release(n->colors.highlight); + n->colors.highlight = gradient_acquire(r->highlight); + } if (COLOR_VALID(r->fc)) { if (save && !COLOR_VALID(n->original->fc)) n->original->fc = n->colors.frame; n->colors.frame = r->fc; } - if (r->format) - RULE_APPLY(format, NULL); if (r->action_name) { - if (save && n->original->action_name) + if (save && n->original->action_name == NULL) n->original->action_name = n->default_action_name; else g_free(n->default_action_name); @@ -77,7 +80,7 @@ void rule_apply(struct rule *r, struct notification *n, bool save) n->default_action_name = g_strdup(r->action_name); } if (r->set_category) { - if (save && n->original->set_category) + if (save && n->original->set_category == NULL) n->original->set_category = n->category; else g_free(n->category); @@ -85,7 +88,7 @@ void rule_apply(struct rule *r, struct notification *n, bool save) n->category = g_strdup(r->set_category); } if (r->default_icon) { - if (save && n->original->default_icon) + if (save && n->original->default_icon == NULL) n->original->default_icon = n->default_icon_name; else g_free(n->default_icon_name); @@ -93,7 +96,7 @@ void rule_apply(struct rule *r, struct notification *n, bool save) n->default_icon_name = g_strdup(r->default_icon); } if (r->set_stack_tag) { - if (save && !n->original->set_stack_tag) + if (save && n->original->set_stack_tag == NULL) n->original->set_stack_tag = n->stack_tag; else g_free(n->stack_tag); @@ -101,7 +104,7 @@ void rule_apply(struct rule *r, struct notification *n, bool save) n->stack_tag = g_strdup(r->set_stack_tag); } if (r->new_icon) { - if (save && !n->original->new_icon) + if (save && n->original->new_icon == NULL) n->original->new_icon = g_strdup(n->iconname); // FIXME This is not efficient when the icon is replaced @@ -111,9 +114,19 @@ void rule_apply(struct rule *r, struct notification *n, bool save) notification_icon_replace_path(n, r->new_icon); n->receiving_raw_icon = false; } + if (r->format != NULL) { + if (save && n->original->format == NULL) + n->original->format = n->format; + else + g_free(n->format); + + n->format = g_strdup(r->format); + } if (r->script) { - if (save && !n->original->script && n->script_count > 0) - n->original->script = n->scripts[0]; + if (save && n->original->script == NULL) + n->original->script = n->script_count > 0 + ? g_strdup(n->scripts[0]) + : g_strdup(r->script); n->scripts = g_renew(char *, n->scripts, n->script_count + 2); n->scripts[n->script_count] = g_strdup(r->script); @@ -235,15 +248,24 @@ void rule_free(struct rule *r) if (r == NULL || r == &empty_rule) return; + g_free(r->name); + g_free(r->appname); + g_free(r->summary); + g_free(r->body); + g_free(r->icon); + g_free(r->category); + g_free(r->stack_tag); + g_free(r->desktop_entry); + g_free(r->action_name); - g_free(r->set_category); - g_free(r->default_icon); - g_free(r->set_stack_tag); g_free(r->new_icon); - g_free(r->name); + g_free(r->default_icon); + gradient_release(r->highlight); - if (r->highlight_owned) - gradient_free(r->highlight); + g_free(r->set_category); + g_free(r->format); + g_free(r->script); + g_free(r->set_stack_tag); } diff --git a/src/rules.h b/src/rules.h index dae9b5ada..bdeb17004 100644 --- a/src/rules.h +++ b/src/rules.h @@ -51,11 +51,10 @@ struct rule { struct color fg; struct color bg; struct gradient *highlight; - bool highlight_owned; struct color fc; char *set_category; - const char *format; - const char *script; + char *format; + char *script; enum behavior_fullscreen fullscreen; bool enabled; int progress_bar_alignment; diff --git a/src/settings.c b/src/settings.c index 9e388ba9e..515911f46 100644 --- a/src/settings.c +++ b/src/settings.c @@ -32,6 +32,7 @@ #endif struct settings settings; +bool print_notifications = false; /** @brief Filter for scandir(). * @@ -141,16 +142,6 @@ FILE *fopen_conf(char * const path) return f; } -void settings_init(void) { - static bool init_done = false; - if (!init_done) { - LOG_D("Initializing settings"); - settings = (struct settings) {0}; - - init_done = true; - } -} - void check_and_correct_settings(struct settings *s) { #ifndef ENABLE_WAYLAND @@ -270,10 +261,6 @@ static void process_conf_file(const gpointer conf_fname, gpointer n_success) { void load_settings(char **const config_paths) { - // NOTE: settings_init should be called at the start of dunst_main, otherwise - // the cmdline settings would be reset - settings_init(); - LOG_D("Setting defaults"); set_defaults(); @@ -302,9 +289,33 @@ void load_settings(char **const config_paths) void settings_free(struct settings *s) { - gradient_free(s->colors_low.highlight); - gradient_free(s->colors_norm.highlight); - gradient_free(s->colors_crit.highlight); + gradient_release(s->colors_low.highlight); + gradient_release(s->colors_norm.highlight); + gradient_release(s->colors_crit.highlight); + + g_free(s->font); + g_free(s->format); + g_free(s->icons[0]); + g_free(s->icons[1]); + g_free(s->icons[2]); + g_free(s->title); + g_free(s->class); + g_free(s->monitor); + g_free(s->dmenu); + g_strfreev(s->dmenu_cmd); + g_free(s->browser); + g_strfreev(s->browser_cmd); + g_strfreev(s->icon_theme); + g_free(s->icon_path); + + g_free(s->mouse_left_click); + g_free(s->mouse_middle_click); + g_free(s->mouse_right_click); + + g_free(s->close_ks.str); + g_free(s->close_all_ks.str); + g_free(s->history_ks.str); + g_free(s->context_ks.str); } /* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/settings.h b/src/settings.h index afaa9b76c..653c8623c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -14,7 +14,7 @@ // Note: Wayland doesn't support hotkeys struct keyboard_shortcut { - const char *str; + char *str; #ifdef ENABLE_X11 KeyCode code; KeySym sym; @@ -180,8 +180,7 @@ struct settings { }; extern struct settings settings; - -void settings_init(void); +extern bool print_notifications; void load_settings(char **const config_paths); diff --git a/test/helpers.c b/test/helpers.c index 47f6d4856..74381d851 100644 --- a/test/helpers.c +++ b/test/helpers.c @@ -51,8 +51,7 @@ struct notification *test_notification(const char *name, gint64 timeout) struct notification *n = test_notification_uninitialized(name); notification_init(n); - - n->format = "%s\n%b"; + notification_replace_format(n, "%s\n%b"); if (timeout != -1) n->timeout = S2US(timeout); diff --git a/test/notification.c b/test/notification.c index 392580c79..58a551958 100644 --- a/test/notification.c +++ b/test/notification.c @@ -218,7 +218,7 @@ TEST test_notification_icon_scaling_notneeded(void) TEST test_notification_format_message(struct notification *n, const char *format, const char *exp) { - n->format = format; + notification_replace_format(n, format); notification_format_message(n); ASSERT_STR_EQ(exp, n->msg); @@ -230,7 +230,7 @@ TEST test_notification_maxlength(void) { unsigned int len = 5005; struct notification *n = notification_create(); - n->format = "%a"; + notification_replace_format(n, "%a"); n->appname = g_malloc(len + 1); n->appname[len] = '\0'; diff --git a/test/option_parser.c b/test/option_parser.c index 9c85e3998..f2113a7bd 100644 --- a/test/option_parser.c +++ b/test/option_parser.c @@ -383,7 +383,7 @@ TEST test_string_to_list(void) {MOUSE_CLOSE_ALL, MOUSE_CLOSE_CURRENT, MOUSE_CLOSE_ALL, MOUSE_ACTION_END}, }; - static char buf[50]; + static char buf[100]; for (int i = 0; i < G_N_ELEMENTS(inputs); i++) { sprintf(buf, "Failed in round %i", i); ASSERTm(buf, set_from_string(s.value, s, inputs[i])); @@ -783,12 +783,12 @@ TEST test_string_to_gradient(void) for (int k = 0; k < grad->length; k++) ASSERTm(buf, COLOR_SAME(grad->colors[k], results[i]->colors[k])); - gradient_free(grad); + gradient_release(grad); grad = NULL; } for (int i = 0; i < G_N_ELEMENTS(results); i++) - gradient_free(results[i]); + gradient_release(results[i]); PASS(); } From 9eb9017d1f7fb3822ead78e45685bdb69a40b499 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Sat, 14 Dec 2024 00:31:11 +0100 Subject: [PATCH 3/4] Free rules when reloading --- src/dunst.c | 3 +++ src/notification.c | 4 +--- src/rules.c | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dunst.c b/src/dunst.c index a23de5a68..bce7b980b 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -223,6 +223,9 @@ void reload(char **const configs) setup_done = false; draw_deinit(); + g_slist_free_full(rules, (GDestroyNotify)rule_free); + rules = NULL; + settings_free(&settings); load_settings(configs); diff --git a/src/notification.c b/src/notification.c index ce7f86070..a504ba2a2 100644 --- a/src/notification.c +++ b/src/notification.c @@ -297,10 +297,8 @@ void notification_unref(struct notification *n) if (!g_atomic_int_dec_and_test(&n->priv->refcount)) return; - if (n->original) { + if (n->original) rule_free(n->original); - g_free(n->original); - } g_free(n->dbus_client); g_free(n->appname); diff --git a/src/rules.c b/src/rules.c index 978fde11d..4e41251ec 100644 --- a/src/rules.c +++ b/src/rules.c @@ -266,6 +266,8 @@ void rule_free(struct rule *r) g_free(r->format); g_free(r->script); g_free(r->set_stack_tag); + + g_free(r); } From 5642325ed6d21b8ece85006c9602d9872c6ca894 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Sat, 14 Dec 2024 00:39:48 +0100 Subject: [PATCH 4/4] Fix another memleak --- src/settings.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/settings.c b/src/settings.c index 515911f46..6b83fe053 100644 --- a/src/settings.c +++ b/src/settings.c @@ -88,6 +88,7 @@ static void config_files_add_drop_ins(GPtrArray *config_files, const char *path) if (n == -1) { // Scandir error. Most likely the directory doesn't exist. + g_free(drop_in_dir); return; } @@ -98,6 +99,8 @@ static void config_files_add_drop_ins(GPtrArray *config_files, const char *path) g_ptr_array_insert(config_files, insert_index, drop_in); g_free(drop_ins[n]); } + + g_free(drop_in_dir); g_free(drop_ins); }