]> git.scripts.mit.edu Git - git.git/commit
config: clarify memory ownership when preparing comment strings
authorPatrick Steinhardt <ps@pks.im>
Mon, 6 May 2024 08:55:56 +0000 (10:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 May 2024 18:50:07 +0000 (11:50 -0700)
commita78b462976d36304212f93b6d4a4c086a007362f
tree3cc9c03f6fa7544255fe1347a5555a4de6778709
parent786a3e4b8d754d2b14b1208b98eeb0a554ef19a8
config: clarify memory ownership when preparing comment strings

The ownership of memory returned when preparing a comment string is
quite intricate: when the returned value is different than the passed
value, then the caller is responsible to free the memory. This is quite
subtle, and it's even easier to miss because the returned value is in
fact a `const char *`.

Adapt the function to always return either `NULL` or a newly allocated
string. The function is called at most once per git-config(1), so it's
not like this micro-optimization really matters. Thus, callers are now
always responsible for freeing the value.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/config.c
config.c
config.h