diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-02-22 16:12:43 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-02-22 16:12:43 -0800 |
commit | 45df6c4d756df25d04f82f4803923baaf0c12a33 (patch) | |
tree | b30ad9c606be7977d5dd5df0f35d91b1450aea55 /diff.c | |
parent | dcb11fc6225edbe2bd7af63eb550b739e7f4a074 (diff) | |
parent | c45dc9cf30a6f7f40adb3ea70dd2f2905ecd4afa (diff) |
Merge branch 'ab/diff-deferred-free'
A small memleak in "diff -I<regexp>" has been corrected.
* ab/diff-deferred-free:
diff: plug memory leak from regcomp() on {log,diff} -I
diff: add an API for deferred freeing
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 32 |
1 files changed, 28 insertions, 4 deletions
@@ -6336,6 +6336,32 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o) } } +static void diff_free_file(struct diff_options *options) +{ + if (options->close_file) + fclose(options->file); +} + +static void diff_free_ignore_regex(struct diff_options *options) +{ + int i; + + for (i = 0; i < options->ignore_regex_nr; i++) { + regfree(options->ignore_regex[i]); + free(options->ignore_regex[i]); + } + free(options->ignore_regex); +} + +void diff_free(struct diff_options *options) +{ + if (options->no_free) + return; + + diff_free_file(options); + diff_free_ignore_regex(options); +} + void diff_flush(struct diff_options *options) { struct diff_queue_struct *q = &diff_queued_diff; @@ -6399,8 +6425,7 @@ void diff_flush(struct diff_options *options) * options->file to /dev/null should be safe, because we * aren't supposed to produce any output anyway. */ - if (options->close_file) - fclose(options->file); + diff_free_file(options); options->file = xfopen("/dev/null", "w"); options->close_file = 1; options->color_moved = 0; @@ -6433,8 +6458,7 @@ void diff_flush(struct diff_options *options) free_queue: free(q->queue); DIFF_QUEUE_CLEAR(q); - if (options->close_file) - fclose(options->file); + diff_free(options); /* * Report the content-level differences with HAS_CHANGES; |