From 1e477395d9c93e3ec9dd0c113eec33874442515d Mon Sep 17 00:00:00 2001 From: John Chen Date: Sat, 21 Jan 2017 14:38:36 +0800 Subject: [PATCH] Fix #281 bad free. Also fix a memory leak. (#282) * Fix #281 bad free. Also fix a memory leak. With `n->icon = r->new_icon` and later `free(n->icon)` `r->new_icon` is wrongly freed. Fix that with strdup. Also fix an obvious memory leak by the way. --- src/rules.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rules.c b/src/rules.c index dc8e465..d568218 100644 --- a/src/rules.c +++ b/src/rules.c @@ -19,8 +19,11 @@ void rule_apply(rule_t * r, notification * n) n->allow_markup = r->allow_markup; if (r->plain_text != -1) n->plain_text = r->plain_text; - if (r->new_icon) - n->icon = r->new_icon; + if (r->new_icon) { + if(n->icon) + g_free(n->icon); + n->icon = g_strdup(r->new_icon); + } if (r->fg) n->color_strings[ColFG] = r->fg; if (r->bg)