🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.git
2 messages
2 total messages Started by Junio C Hamano Tue, 24 Nov 2026 21:34
Re: [PATCH 4/6] packfile: introduce function to free a packfile
#3739
Author: Junio C Hamano
Date: Tue, 24 Nov 2026 21:34
33 lines
13691 bytes
Patrick Steinhardt <ps@pks.im> writes:

> 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.

> +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)?
Re: [PATCH 4/6] packfile: introduce function to free a packfile
#3932
Author: Junio C Hamano
Date: Thu, 26 Nov 2026 20:41
32 lines
13893 bytes
Toon Claes <toon@iotcl.com> writes:

>> 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)?
>
> Yeah, I was wondering about that as well, because there are a few
> callsites doing `if (X) _free(X);`. Having the _free() function
> NULL-safe would simplify them.
>
> For what it's worth, the pattern isn't described in CodingGuidelines, so
> technically speaking it's fine. But I wouldn't mind extending the
> guidelines to adopt the second kind.

Yeah.  Helpers that are file-scope static may not matter, but we may
want to standardise public helpers like this one, especially the ones
named TYPEOFTHETHING_free().

Thanks.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads