summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2013-09-24 05:19:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-10-15 21:46:31 (GMT)
commit11a6ba1c012e8275c70032fb2e847740a2f61865 (patch)
tree84751bc478448f487a9b4ab99b7004b19d741b6f /remote.c
parent02a110ad435a6ccda648f09f94e546dfd7bdd0ac (diff)
downloadgit-11a6ba1c012e8275c70032fb2e847740a2f61865.zip
git-11a6ba1c012e8275c70032fb2e847740a2f61865.tar.gz
git-11a6ba1c012e8275c70032fb2e847740a2f61865.tar.bz2
remote: do not copy "origin" string literal
Our default_remote_name starts at "origin", but may be overridden by the config file. In the former case, we allocate a new string, but in the latter case, we point to the remote name in an existing "struct branch". This gives the variable inconsistent free() semantics (we are sometimes responsible for freeing the string and sometimes pointing to somebody else's storage), and causes a small leak when the allocated string is overridden by config. We can fix both by simply dropping the extra copy and pointing to the string literal. Noticed-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/remote.c b/remote.c
index efcba93..ffd1a65 100644
--- a/remote.c
+++ b/remote.c
@@ -480,7 +480,7 @@ static void read_config(void)
int flag;
if (default_remote_name) /* did this already */
return;
- default_remote_name = xstrdup("origin");
+ default_remote_name = "origin";
current_branch = NULL;
head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
if (head_ref && (flag & REF_ISSYMREF) &&