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>
Jeff King committed
Sep 24, 2013 at 01:19 UTC
11a6ba1c012e8275c70032fb2e847740a2f61865
1 file changed
+1
-1
remote.c
+1
-1
@@ -480,7 +480,7 @@ static void read_config(void)
480
int flag;
481
if (default_remote_name) /* did this already */
482
return;
483
- default_remote_name = xstrdup("origin");
483
+ default_remote_name = "origin";
484
current_branch = NULL;
485
head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
486
if (head_ref && (flag & REF_ISSYMREF) &&