diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-05-15 13:59:04 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-05-15 13:59:05 -0700 |
commit | 1e1dcb2a423cad350e8f20fdcc957064e5cff528 (patch) | |
tree | d32cc86771285117dec8eeda9ac45b1f931fc5e9 /diff.c | |
parent | cd2b740ca95291b81b8e75000d2ee76b4f735877 (diff) | |
parent | 83973981eb475ce90f829f8a5bd6ea99cd3bbd8e (diff) | |
download | git-1e1dcb2a423cad350e8f20fdcc957064e5cff528.tar.gz |
Merge branch 'jc/dirstat-plug-leaks'
"git diff --dirstat" leaked memory, which has been plugged.
* jc/dirstat-plug-leaks:
diff: plug leaks in dirstat
diff: refactor common tail part of dirstat computation
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -3007,6 +3007,24 @@ static int dirstat_compare(const void *_a, const void *_b) return strcmp(a->name, b->name); } +static void conclude_dirstat(struct diff_options *options, + struct dirstat_dir *dir, + unsigned long changed) +{ + struct dirstat_file *to_free = dir->files; + + if (!changed) { + /* This can happen even with many files, if everything was renames */ + ; + } else { + /* Show all directories with more than x% of the changes */ + QSORT(dir->files, dir->nr, dirstat_compare); + gather_dirstat(options, dir, changed, "", 0); + } + + free(to_free); +} + static void show_dirstat(struct diff_options *options) { int i; @@ -3096,13 +3114,7 @@ found_damage: dir.nr++; } - /* This can happen even with many files, if everything was renames */ - if (!changed) - return; - - /* Show all directories with more than x% of the changes */ - QSORT(dir.files, dir.nr, dirstat_compare); - gather_dirstat(options, &dir, changed, "", 0); + conclude_dirstat(options, &dir, changed); } static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *options) @@ -3140,13 +3152,7 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o dir.nr++; } - /* This can happen even with many files, if everything was renames */ - if (!changed) - return; - - /* Show all directories with more than x% of the changes */ - QSORT(dir.files, dir.nr, dirstat_compare); - gather_dirstat(options, &dir, changed, "", 0); + conclude_dirstat(options, &dir, changed); } static void free_diffstat_file(struct diffstat_file *f) |