Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory corruption when reloading #1413

Merged
merged 4 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix gradient ownership in rule
  • Loading branch information
bynect committed Dec 10, 2024
commit 1b37ab503d6955cee23ecaaf633558ae7d24afdb
1 change: 1 addition & 0 deletions src/dunst.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions src/option_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
7 changes: 2 additions & 5 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
1 change: 1 addition & 0 deletions src/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading