Re: [PATCH 05/13] run_diff_files: avoid memory leak
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jul 4, 2026, 08:58 UTC
- Message-ID
- <ac7844ee-a401-76b7-56aa-6318e2bdcc4a@gmx.de>
- In-Reply-To
- <akTIMM6qLfDNdg-a@pks.im>
Hi Patrick,
On Wed, 1 Jul 2026, Patrick Steinhardt wrote:
Show 26 quoted lines
> On Wed, Jul 01, 2026 at 07:04:23AM +0000, Johannes Schindelin via GitGitGadget wrote:
> > 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;
>
> Huh. There is no assignment between the variable declaration and this
> call to `continue`, so how could this ever plug a memory leak? None of
> the other paths seem to leak the variable, either.You are right; the patch as posted plugs nothing.
The reason it looks pointless is that the leak it was written against was fixed independently in the meantime by 949bb8f74f4a (run_diff_files(): delay allocation of combine_diff_path, 2025-01-09), which moved the `dpath = xmalloc(...)` to after the `check_removed()` call. Before that reordering, the two `continue` statements did leak the just-allocated `dpath` (originally introduced by 4fc970c43884, 2007-02-25).
I had missed that when picking back up the work on addressing Coverity reports, sorry! I will drop this patch from v2.
Ciao, Johannes