Skip to content

Commit

Permalink
branch.c: use 'goto cleanup' in setup_tracking() to fix memory leaks
Browse files Browse the repository at this point in the history
Signed-off-by: Glen Choo <chooglen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
chooglen authored and gitster committed Feb 4, 2022
1 parent 961b130 commit 679e369
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
if (track != BRANCH_TRACK_INHERIT)
for_each_remote(find_tracked_branch, &tracking);
else if (inherit_tracking(&tracking, orig_ref))
return;
goto cleanup;

if (!tracking.matches)
switch (track) {
Expand All @@ -249,7 +249,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
case BRANCH_TRACK_INHERIT:
break;
default:
return;
goto cleanup;
}

if (tracking.matches > 1)
Expand All @@ -262,7 +262,8 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
tracking.remote, tracking.srcs) < 0)
exit(-1);

string_list_clear(tracking.srcs, 0);
cleanup:
string_list_clear(&tracking_srcs, 0);
}

int read_branch_desc(struct strbuf *buf, const char *branch_name)
Expand Down

0 comments on commit 679e369

Please sign in to comment.