[PATCH 05/13] run_diff_files: avoid memory leak
- From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Jul 1, 2026, 07:04 UTC
- Message-ID
- <860bc8f52dc9be8bbfafcda296be831a1ffaf1c2.1782889472.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2163.git.1782889472.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
In 4fc970c4388 (diff --cc: fix display of symlink conflicts during a merge., 2007-02-25) a conditional block was introduced in `run_diff_files()` that skips the rest of the loop iteration and advances directly to the next iteration.
However, it missed that there was a similar conditional block that was last touched in b4b1550315c (Don't instantiate structures with FAMs., 2006-06-18) and which demonstrated that the `dpath` structure needed to be released.
Let's fix this.
Pointed out by Coverity.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- diff-lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/diff-lib.c b/diff-lib.c index ae91027a02..7ba839b4a8 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -152,7 +152,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option) continue; if (ce_stage(ce)) { - struct combine_diff_path *dpath; + struct combine_diff_path *dpath = NULL; struct diff_filepair *pair; unsigned int wt_mode = 0; int num_compare_stages = 0; @@ -164,6 +164,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option) else { if (changed < 0) { perror(ce->name); + free(dpath); continue; } wt_mode = 0;
-- gitgitgadget