Skip to content

Commit 1533bda

Browse files
rjustogitster
authored andcommitted
branch: fix a leak in dwim_and_setup_tracking
In e89f151 (branch: move --set-upstream-to behavior to dwim_and_setup_tracking(), 2022-01-28) the string returned by dwim_branch_start() was not freed, resulting in a memory leak. It can be reviewed with: $ git remote add local . $ git update-ref refs/remotes/local/foo HEAD $ git branch --set-upstream-to local/foo foo Direct leak of 23 byte(s) in 1 object(s) allocated from: ... in xstrdup wrapper.c ... in expand_ref refs.c ... in repo_dwim_ref refs.c ... in dwim_branch_start branch.c ... in dwim_and_setup_tracking branch.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Let's free it now. Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4689101 commit 1533bda

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

branch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,10 @@ void dwim_and_setup_tracking(struct repository *r, const char *new_ref,
638638
const char *orig_ref, enum branch_track track,
639639
int quiet)
640640
{
641-
char *real_orig_ref;
641+
char *real_orig_ref = NULL;
642642
dwim_branch_start(r, orig_ref, track, &real_orig_ref, NULL);
643643
setup_tracking(new_ref, real_orig_ref, track, quiet);
644+
free(real_orig_ref);
644645
}
645646

646647
/**

0 commit comments

Comments
 (0)