Skip to content

Commit

Permalink
Fix double free
Browse files Browse the repository at this point in the history
  • Loading branch information
bynect committed Aug 17, 2024
1 parent be4f1bd commit 4fe05fe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 6 additions & 1 deletion test/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 4fe05fe

Please sign in to comment.