cmd_config(): make a copy of path obtained from git_path()
The strings returned by git_path() are recycled after a while. Make a copy of the config filename rather than holding onto the return value from git_path(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Nov 16, 2014 at 08:37 UTC
3696a7c2d9a4f3227dd7719b734e9db242aae6af
1 file changed
+5
-2
builtin/config.c
+5
-2
@@ -568,8 +568,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
568
}
569
}
570
else if (actions == ACTION_EDIT) {
571
- const char *config_file = given_config_source.file ?
572
- given_config_source.file : git_path("config");
571
+ char *config_file;
572
+
573
check_argc(argc, 0, 0);
574
if (!given_config_source.file && nongit)
575
die("not in a git directory");
@@ -578,6 +578,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
578
if (given_config_source.blob)
579
die("editing blobs is not supported");
580
git_config(git_default_config, NULL);
581
+ config_file = xstrdup(given_config_source.file ?
582
+ given_config_source.file : git_path("config"));
583
if (use_global_config) {
584
int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
585
if (fd) {
@@ -590,6 +592,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
592
die_errno(_("cannot create configuration file %s"), config_file);
593
}
594
launch_editor(config_file, NULL, NULL);
595
+ free(config_file);
596
}
597
else if (actions == ACTION_SET) {
598
int ret;