Skip to content

Commit 6b15d9c

Browse files
pks-tgitster
authored andcommitted
diff: fix leak when parsing invalid ignore regex option
When parsing invalid ignore regexes passed via the `-I` option we don't free already-allocated memory, leading to a memory leak. Fix this. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4dfd4f1 commit 6b15d9c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

diff.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5464,9 +5464,13 @@ static int diff_opt_ignore_regex(const struct option *opt,
54645464
regex_t *regex;
54655465

54665466
BUG_ON_OPT_NEG(unset);
5467+
54675468
regex = xmalloc(sizeof(*regex));
5468-
if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE))
5469+
if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) {
5470+
free(regex);
54695471
return error(_("invalid regex given to -I: '%s'"), arg);
5472+
}
5473+
54705474
ALLOC_GROW(options->ignore_regex, options->ignore_regex_nr + 1,
54715475
options->ignore_regex_alloc);
54725476
options->ignore_regex[options->ignore_regex_nr++] = regex;

t/t4013-diff-various.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test_description='Various diff formatting options'
88
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
99
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1010

11+
TEST_PASSES_SANITIZE_LEAK=true
1112
. ./test-lib.sh
1213
. "$TEST_DIRECTORY"/lib-diff.sh
1314

0 commit comments

Comments
 (0)