]> git.ipfire.org Git - thirdparty/git.git/commitdiff
grep: fix leaking grep pattern
authorPatrick Steinhardt <ps@pks.im>
Thu, 26 Sep 2024 11:46:54 +0000 (13:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Sep 2024 15:25:36 +0000 (08:25 -0700)
When creating a pattern via `create_grep_pat()` we allocate the pattern
member of the structure regardless of the token type. But later, when we
try to free the structure, we free the pattern member conditionally on
the token type and thus leak memory.

Plug this leak. The leak is exposed by t7814, but plugging it alone does
not make the whole test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c

diff --git a/grep.c b/grep.c
index e5761426e4f0f343a07ef99191674f50215a2bd2..701e58de04ef61d5c183200d96919cbc794f5d53 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -843,11 +843,11 @@ static void free_grep_pat(struct grep_pat *pattern)
                                free_pcre2_pattern(p);
                        else
                                regfree(&p->regexp);
-                       free(p->pattern);
                        break;
                default:
                        break;
                }
+               free(p->pattern);
                free(p);
        }
 }