branch: fix a leak in dwim_and_setup_tracking
In e89f151db1
(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 <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
4689101a40
commit
1533bda770
3
branch.c
3
branch.c
@ -638,9 +638,10 @@ void dwim_and_setup_tracking(struct repository *r, const char *new_ref,
|
||||
const char *orig_ref, enum branch_track track,
|
||||
int quiet)
|
||||
{
|
||||
char *real_orig_ref;
|
||||
char *real_orig_ref = NULL;
|
||||
dwim_branch_start(r, orig_ref, track, &real_orig_ref, NULL);
|
||||
setup_tracking(new_ref, real_orig_ref, track, quiet);
|
||||
free(real_orig_ref);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user