From: Jeff Smith Date: Mon, 20 Mar 2017 19:24:40 +0000 (-0500) Subject: killall: free regular expression list entries X-Git-Tag: v23.0~15^2^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=564b17d2b0dd246f23bec123d23398ce64096041;p=psmisc killall: free regular expression list entries Noticed when running tool in valgrind --- diff --git a/src/killall.c b/src/killall.c index a8e6d9a..a51c1e9 100644 --- a/src/killall.c +++ b/src/killall.c @@ -219,6 +219,15 @@ match_process_uid(pid_t pid, uid_t uid) return re; } +static void +free_regexp_list(regex_t *reglist, int names) +{ + int i; + for (i = 0; i < names; i++) + regfree(®list[i]); + free(reglist); +} + static regex_t * build_regexp_list(int names, char **namelist) { @@ -240,6 +249,7 @@ build_regexp_list(int names, char **namelist) if (regcomp(®list[i], namelist[i], flag) != 0) { fprintf(stderr, _("killall: Bad regular expression: %s\n"), namelist[i]); + free_regexp_list(reglist, i); exit (1); } } @@ -626,7 +636,8 @@ kill_all (int signal, int name_count, char **namelist, struct passwd *pwent) } if (command) free(command); - free(reglist); + if (reglist) + free_regexp_list(reglist, name_count); free(pgids); if (!quiet) for (i = 0; i < name_count; i++)