]> granicus.if.org Git - procps-ng/commitdiff
pgrep: Remove memory leak
authorCraig Small <csmall@dropbear.xyz>
Tue, 22 Dec 2020 05:14:56 +0000 (16:14 +1100)
committerCraig Small <csmall@dropbear.xyz>
Tue, 22 Dec 2020 05:14:56 +0000 (16:14 +1100)
This is part of !118 where @tt.rantala found a memory leak.
The other part of !118 may come later if the performance change
is significant.

References:
 procps-ng/procps!118

pgrep.c

diff --git a/pgrep.c b/pgrep.c
index 3e2a67ecdfb11784fa756d8182ca42a9ac600a7f..c0ebc558e1e4bcb360c2490bc4b7e7299b5fc2d8 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -663,6 +663,11 @@ static struct el * select_procs (int *num)
     free(cmdsearch);
     free(cmdoutput);
 
+    if (preg) {
+        regfree(preg);
+        free(preg);
+    }
+
     *num = matches;
 
     if ((!matches) && (!opt_full) && opt_pattern && (strlen(opt_pattern) > 15))