Re: [PATCH 09/21] builtin/config: move location options into local variables
- From
Patrick Steinhardt <ps@pks.im>
- Date
- May 10, 2024, 11:34 UTC
- Message-ID
- <Zj4GLqRQCfOrmz6d@tanuki>
- In-Reply-To
- <a96c122280ad025f94c1343cca85c67c7c617c8f.1715339393.git.ps@pks.im>
On Fri, May 10, 2024 at 01:25:07PM +0200, Patrick Steinhardt wrote:
> @@ -638,34 +657,40 @@ static char *default_user_config(void)
[snip]
Show 6 quoted lines
> - if (use_global_config) {
> - given_config_source.file = git_global_config();
> - if (!given_config_source.file)
> + if (opts->use_global_config) {
> + opts->source.file = xstrdup_or_null(git_global_config());
> + if (!opts->source.file)This needs the following on top to plug a memory leak -- I didn't realize that `git_global_config()` transfers ownership of the string to the caller already.
diff --git a/builtin/config.c b/builtin/config.c index 127bc097b2..30a49d07d7 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -761,7 +761,7 @@ static void location_options_init(struct config_location_options *opts, } if (opts->use_global_config) { - opts->source.file = xstrdup_or_null(git_global_config()); + opts->source.file = git_global_config(); if (!opts->source.file) /* * It is unknown if HOME/.gitconfig exists, so Will fix in v2. Patrick