Skip to content

Commit c45dc9c

Browse files
avargitster
authored andcommitted
diff: plug memory leak from regcomp() on {log,diff} -I
Fix a memory leak in 296d4a9 (diff: add -I<regex> that ignores matching changes, 2020-10-20) by freeing the memory it allocates in the newly introduced diff_free(). See the previous commit for details on that. This memory leak was intentionally introduced in 296d4a9, see the discussion on a previous iteration of it in https://lore.kernel.org/git/[email protected]/ At that time freeing the memory was somewhat tedious, but since it isn't anymore with the newly introduced diff_free() let's use it. Let's retain the pattern for diff_free_file() and add a diff_free_ignore_regex(), even though (unlike "diff_free_file") we don't need to call it elsewhere. I think this'll make for more readable code than gradually accumulating a giant diff_free() function, sharing "int i" across unrelated code etc. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e900d49 commit c45dc9c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

diff.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6342,12 +6342,24 @@ static void diff_free_file(struct diff_options *options)
63426342
fclose(options->file);
63436343
}
63446344

6345+
static void diff_free_ignore_regex(struct diff_options *options)
6346+
{
6347+
int i;
6348+
6349+
for (i = 0; i < options->ignore_regex_nr; i++) {
6350+
regfree(options->ignore_regex[i]);
6351+
free(options->ignore_regex[i]);
6352+
}
6353+
free(options->ignore_regex);
6354+
}
6355+
63456356
void diff_free(struct diff_options *options)
63466357
{
63476358
if (options->no_free)
63486359
return;
63496360

63506361
diff_free_file(options);
6362+
diff_free_ignore_regex(options);
63516363
}
63526364

63536365
void diff_flush(struct diff_options *options)

0 commit comments

Comments
 (0)