Re: Re*: [PATCH] change contract between system_path and it's callers
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 25, 2014, 20:20 UTC
- Message-ID
- <xmqqk32jrq11.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <CANCZXo4=D=RPnGeAfcvD0O1hX0B43z1b11gyzjbJYGXzusfFYg@mail.gmail.com>
Alexander Kuleshov <kuleshovmail@gmail.com> writes:
> Ah, you little ahead me, so we do not care about config.c in this way, > because it takes git_etc_gitconfig() in the same way as > git_etc_gitattributes
Yes, but looking at the file, you would notice that the "use_local_config" codepath assigns a string obtained from git_pathdup() to given_config_source.file, which means that somebody later in the code path would not know if given_config_source.file is merely pointing at a piece of memory owned by somebody else (e.g. came from git_etc_gitconfig()) or if it owns the piece of memory (e.g. came from git_pathdup()). In the former case the memory should never be freed, but not freeing in the latter would leak the memory.
Assignment to given_config_source.file I see in that function that borrows (i.e. the current code that does not fee is correct) are:
- getenv(CONFIG_ENVIRONMENT) - NULL ;-) obviously - git_etc_gitconfig() All the other assignment to given_config_source.file (including the ones obtained from a call to home_config_paths()) makes us responsible to free that piece memory, so they are technically leaks.
But cmd_config() is a moral equivalent of main() in a typical program, so it might not be worth worrying about allocating a single piece of memory that is used throughout the lifetime of that function and leaving it without freeing.