From: Jeff King Date: Tue, 24 Sep 2013 05:19:08 +0000 (-0400) Subject: remote: do not copy "origin" string literal X-Git-Tag: v1.8.5-rc0~22^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/11a6ba1c012e8275c70032fb2e847740a2f61865 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 Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/remote.c b/remote.c index efcba931ec..ffd1a6523e 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) &&