From 4779e59c509c72bc7431fe2fab47c16342ef8d6b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ingo=20B=C3=BCrk?= Date: Wed, 28 Oct 2015 14:39:23 +0100 Subject: [PATCH] Fix multiple memory leaks with regular expressions. --- src/config_directives.c | 1 + src/manage.c | 1 + src/match.c | 16 +++++++--------- src/regex.c | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/config_directives.c b/src/config_directives.c index cd0432fe..fdfc1c7d 100644 --- a/src/config_directives.c +++ b/src/config_directives.c @@ -29,6 +29,7 @@ CFGFUN(criteria_init, int _state) { criteria_next_state = _state; DLOG("Initializing criteria, current_match = %p, state = %d\n", current_match, _state); + match_free(current_match); match_init(current_match); } diff --git a/src/manage.c b/src/manage.c index 5cfe490e..0dec2844 100644 --- a/src/manage.c +++ b/src/manage.c @@ -294,6 +294,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki if (match != NULL && match->insert_where != M_BELOW) { DLOG("Removing match %p from container %p\n", match, nc); TAILQ_REMOVE(&(nc->swallow_head), match, matches); + match_free(match); } } diff --git a/src/match.c b/src/match.c index 67054dae..2cdf4f45 100644 --- a/src/match.c +++ b/src/match.c @@ -238,21 +238,13 @@ bool match_matches_window(Match *match, i3Window *window) { * */ void match_free(Match *match) { - /* First step: free the regex fields / patterns */ regex_free(match->title); regex_free(match->application); regex_free(match->class); regex_free(match->instance); regex_free(match->mark); regex_free(match->window_role); - - /* Second step: free the regex helper struct itself */ - FREE(match->title); - FREE(match->application); - FREE(match->class); - FREE(match->instance); - FREE(match->mark); - FREE(match->window_role); + regex_free(match->workspace); } /* @@ -264,16 +256,19 @@ void match_parse_property(Match *match, const char *ctype, const char *cvalue) { DLOG("ctype=*%s*, cvalue=*%s*\n", ctype, cvalue); if (strcmp(ctype, "class") == 0) { + regex_free(match->class); match->class = regex_new(cvalue); return; } if (strcmp(ctype, "instance") == 0) { + regex_free(match->instance); match->instance = regex_new(cvalue); return; } if (strcmp(ctype, "window_role") == 0) { + regex_free(match->window_role); match->window_role = regex_new(cvalue); return; } @@ -334,11 +329,13 @@ void match_parse_property(Match *match, const char *ctype, const char *cvalue) { } if (strcmp(ctype, "con_mark") == 0) { + regex_free(match->mark); match->mark = regex_new(cvalue); return; } if (strcmp(ctype, "title") == 0) { + regex_free(match->title); match->title = regex_new(cvalue); return; } @@ -357,6 +354,7 @@ void match_parse_property(Match *match, const char *ctype, const char *cvalue) { } if (strcmp(ctype, "workspace") == 0) { + regex_free(match->workspace); match->workspace = regex_new(cvalue); return; } diff --git a/src/regex.c b/src/regex.c index 913519be..24846981 100644 --- a/src/regex.c +++ b/src/regex.c @@ -64,6 +64,7 @@ void regex_free(struct regex *regex) { FREE(regex->pattern); FREE(regex->regex); FREE(regex->extra); + FREE(regex); } /* -- 2.39.5