Thread (77 messages) 77 messages, 4 authors, 2024-05-15

Re: [PATCH 09/21] builtin/config: move location options into local variables

From: Patrick Steinhardt <hidden>
Date: 2024-05-10 11:34:11
Subsystem: the rest · Maintainer: Linus Torvalds

On Fri, May 10, 2024 at 01:25:07PM +0200, Patrick Steinhardt wrote:
quoted hunk ↗ jump to hunk
@@ -638,34 +657,40 @@ static char *default_user_config(void)
[snip]
-	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

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help