Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 11a6ba1

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 02a110a commit 11a6ba1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static void read_config(void)
480480
int flag;
481481
if (default_remote_name) /* did this already */
482482
return;
483-
default_remote_name = xstrdup("origin");
483+
default_remote_name = "origin";
484484
current_branch = NULL;
485485
head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
486486
if (head_ref && (flag & REF_ISSYMREF) &&

0 commit comments

Comments
 (0)