Re: [PATCH] http: fix memory leak in fetch_and_setup_pack_index()
- From
Jeff King <peff@peff.net>
- Date
- May 29, 2026, 05:32 UTC
- Message-ID
- <20260529053245.GB1099450@coredump.intra.peff.net>
- In-Reply-To
- <aheY6bLM2gxtMDdr@lorenzo-VM>
On Thu, May 28, 2026 at 03:22:49AM +0200, Lorenzo Pegorari wrote:
Show 21 quoted lines
> > So I _think_ we could get away with dropping the existing unlink() call > > and just let it get cleaned up at process exit. But if we are going to > > keep it, do we want to also unlink() in this error path? At which point > > it might make more sense to have an "out" label to consolidate all of > > this cleanup. > > > > If we are going to unlink() here it may also make sense to just return > > the tempfile struct from fetch_pack_index(), and then we can call > > delete_tempfile() on it. See the in-code comment in 63aca3f7f1 which > > mentions this hackery. > > > > So I dunno. I think your patch is doing the right thing as-is, but it > > may be worth taking a moment to clean this up a bit further. > > The `unlink()` indeed is weird. Pointing me to the commit 63aca3f7f1 > really helped me understand how the code changed and the current > situation. Thanks a lot for that. > > I've tried testing as thoroughly as possible whether removing the > `unlink()` function call wouldn't change the expected behavior. > *I think* that it can be removed safely, but I'm not 100% sure yet.
I think the only behavior difference in removing the unlink() is whether we immediately delete the downloaded packfile on error, or if we wait until process exit. From the perspective of somebody calling git-fetch, the outcome is roughly the same (when the process ends, the file is gone). It would only differ if the system crashed before the process ended.
-Peff