{"thread":{"id":"37981","subject":"[PATCH] cmd_config(): Make a copy of path obtained from git_path()","startedAt":"2014-11-16T07:37:44Z","lastAt":"2014-11-17T17:25:07Z","messageCount":2,"participants":["Michael Haggerty","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"251957","messageId":"1416123464-22874-1-git-send-email-mhagger@alum.mit.edu","threadId":"37981","inReplyTo":null,"subject":"[PATCH] cmd_config(): Make a copy of path obtained from git_path()","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-16T07:37:44Z","receivedAt":"2014-11-16T07:37:44Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"The strings returned by git_path() are recycled after a while. So make\na copy of the config filename rather than holding onto the return\nvalue from git_path().\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\nThis patch is an improvement by itself, and it also eases the merging\nto master of my fix for the incorrectly set config file executable\nbit [1].\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/259644\n\n builtin/config.c | 7 +++++--\n 1 file changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 8cc2604..606a3c0 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -568,8 +568,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \telse if (actions == ACTION_EDIT) {\n-\t\tconst char *config_file = given_config_source.file ?\n-\t\t\tgiven_config_source.file : git_path(\"config\");\n+\t\tchar *config_file;\n+\n \t\tcheck_argc(argc, 0, 0);\n \t\tif (!given_config_source.file && nongit)\n \t\t\tdie(\"not in a git directory\");\n@@ -578,6 +578,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tif (given_config_source.blob)\n \t\t\tdie(\"editing blobs is not supported\");\n \t\tgit_config(git_default_config, NULL);\n+\t\tconfig_file = xstrdup(given_config_source.file ?\n+\t\t\t\t      given_config_source.file : git_path(\"config\"));\n \t\tif (use_global_config) {\n \t\t\tint fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);\n \t\t\tif (fd) {\n@@ -590,6 +592,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\t\t\tdie_errno(_(\"cannot create configuration file %s\"), config_file);\n \t\t}\n \t\tlaunch_editor(config_file, NULL, NULL);\n+\t\tfree(config_file);\n \t}\n \telse if (actions == ACTION_SET) {\n \t\tint ret;\n-- \n2.1.1\n"},{"id":"251990","messageId":"xmqqtx1xyc24.fsf@gitster.dls.corp.google.com","threadId":"37981","inReplyTo":"1416123464-22874-1-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH] cmd_config(): Make a copy of path obtained from git_path()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-17T17:25:07Z","receivedAt":"2014-11-17T17:25:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Haggerty <mhagger@alum.mit.edu> writes:\n\n> The strings returned by git_path() are recycled after a while. So make\n> a copy of the config filename rather than holding onto the return\n> value from git_path().\n\nGood thinking.  I agree that is an accident waiting to happen.\n"}]}