Re: [PATCH 08/22] config: fix leaking comment character config
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 8, 2024, 15:54 UTC
- Message-ID
- <xmqq1q2zko2a.fsf@gitster.g>
- In-Reply-To
- <ZrRR9mwyQQrw4Dg5@tanuki>
Patrick Steinhardt <ps@pks.im> writes:
Show 8 quoted lines
> Now that I revisit this commit I'm not quite happy with it anymore. We > still need to have the cast, which is somewhat awkward. I think the > better solution is to instead have a `comment_line_str_allocated` > variable that is non-constant. I'll adapt the code accordingly. > > An even better solution would be to have `struct strbuf` provide an > initializer that populates it with a string constant. But that feels > like a larger undertaking, so I'll leave that for the future.
FWIW, I found the "now we have a variable to refer to the address of the string constant, we can compare to detect if we allocated and need to free" in this round is a good place to stop.
I view the approach to use an auxiliary variable *_allocated is a regression compared to what we see here. The approach makes it easy to forget to futz it when an allocated piece of memory is assigned to the main variable.