Skip to content

Commit

Permalink
Fix memory leak colors given via hints
Browse files Browse the repository at this point in the history
The hints given via DBus are not constants. Therefore those colors have
to get freed. As this is not possible, we have to duplicate the strings
when setting.
  • Loading branch information
bebehei committed Nov 6, 2017
1 parent f8824d6 commit e3238c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ void notification_free(notification *n)
g_free(n->category);
g_free(n->text_to_render);
g_free(n->urls);
g_free(n->colors[ColFG]);
g_free(n->colors[ColBG]);
g_free(n->colors[ColFrame]);

actions_free(n->actions);
rawimage_free(n->raw_icon);
Expand Down Expand Up @@ -348,13 +351,13 @@ void notification_init(notification *n)
/* Color hints */
n->colors[ColFG] = n->colors[ColFG]
? n->colors[ColFG]
: xctx.colors[ColFG][n->urgency];
: g_strdup(xctx.colors[ColFG][n->urgency]);
n->colors[ColBG] = n->colors[ColBG]
? n->colors[ColBG]
: xctx.colors[ColBG][n->urgency];
: g_strdup(xctx.colors[ColBG][n->urgency]);
n->colors[ColFrame] = n->colors[ColFrame]
? n->colors[ColFrame]
: xctx.colors[ColFrame][n->urgency];
: g_strdup(xctx.colors[ColFrame][n->urgency]);

/* Sanitize misc hints */
if (n->progress < 0 || n->progress > 100)
Expand Down
2 changes: 1 addition & 1 deletion src/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ typedef struct _notification {

enum markup_mode markup;
const char *format;
const char *colors[3];
const char *script;
char *colors[3];

/* Hints */
bool transient; /* timeout albeit user is idle */
Expand Down
12 changes: 8 additions & 4 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ void rule_apply(rule_t *r, notification *n)
rawimage_free(n->raw_icon);
n->raw_icon = NULL;
}
if (r->fg)
n->colors[ColFG] = r->fg;
if (r->bg)
n->colors[ColBG] = r->bg;
if (r->fg) {
g_free(n->colors[ColFG]);
n->colors[ColFG] = g_strdup(r->fg);
}
if (r->bg) {
g_free(n->colors[ColBG]);
n->colors[ColBG] = g_strdup(r->bg);
}
if (r->format)
n->format = r->format;
if (r->script)
Expand Down

0 comments on commit e3238c6

Please sign in to comment.