Fix memory leak colors given via hints

The hints given via DBus are not constants. Therefore the color fields
have to get freed during notification cleanup. As it's not possible to
disinguish, which field is constant, we have to duplicate the settings
on assignment.
This commit is contained in:
Benedikt Heine 2017-11-04 18:58:55 +01:00
parent 98d905b8e4
commit b97a49c09b
3 changed files with 15 additions and 8 deletions

View File

@ -214,6 +214,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);
@ -312,11 +315,11 @@ void notification_init(notification *n)
/* Color hints */
if (!n->colors[ColFG])
n->colors[ColFG] = xctx.colors[ColFG][n->urgency];
n->colors[ColFG] = g_strdup(xctx.colors[ColFG][n->urgency]);
if (!n->colors[ColBG])
n->colors[ColBG] = xctx.colors[ColBG][n->urgency];
n->colors[ColBG] = g_strdup(xctx.colors[ColBG][n->urgency]);
if (!n->colors[ColFrame])
n->colors[ColFrame] = xctx.colors[ColFrame][n->urgency];
n->colors[ColFrame] = g_strdup(xctx.colors[ColFrame][n->urgency]);
/* Sanitize misc hints */
if (n->progress < 0 || n->progress > 100)

View File

@ -55,8 +55,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 */

View File

@ -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)