From b97a49c09ba1d5a6033a29f5e84d54bc4e6c46c8 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sat, 4 Nov 2017 18:58:55 +0100 Subject: [PATCH] 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. --- src/notification.c | 9 ++++++--- src/notification.h | 2 +- src/rules.c | 12 ++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/notification.c b/src/notification.c index 7ae2254..5250375 100644 --- a/src/notification.c +++ b/src/notification.c @@ -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) diff --git a/src/notification.h b/src/notification.h index c83077a..5b05e8a 100644 --- a/src/notification.h +++ b/src/notification.h @@ -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 */ diff --git a/src/rules.c b/src/rules.c index da64f9b..7be1abb 100644 --- a/src/rules.c +++ b/src/rules.c @@ -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)