Re: [PATCH 4/6] packfile: introduce function to free a packfile
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 24, 2026, 21:34 UTC
- Message-ID
- <xmqqecc9ncc4.fsf@gitster.g>
- In-Reply-To
- <20261120-pks-packfile-global-statistics-v1-4-19beb83b145f@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 6 quoted lines
> We have a bunch of callsites that want to free a packfile, which > requires them to first close it followed by a call to free(3p). This > feels rather leaky as an abstraction. > > Introduce `packfile_free()` to handle this properly. This function will > also be extended in a subsequent patch to maintain a list of all packs.
OK.
Show 5 quoted lines
> +void packfile_free(struct packed_git *p)
> +{
> + packfile_close(p);
> + free(p);
> +}It seems that we have three kinds of free()-like functions in our system.
- Ones that make it the responsibility of the caller not to pass NULL (this one falls into this category).
- Ones that allows the caller to pass NULL.
- Ones that not just frees, but clears the pointer the caller has to prevent future headaches coming from use-after-free (the caller must pass a pointer to the pointer pointing at the resource being freed).
It seems all the callsites never passes NULL to this function, so this is fine as-is, but I wonder if we want to move it to the second category by guarding against NULL, making it behave similar to free(NULL)?