Skip to content

Commit 679e369

Browse files
chooglengitster
authored andcommitted
branch.c: use 'goto cleanup' in setup_tracking() to fix memory leaks
Signed-off-by: Glen Choo <[email protected]> Reviewed-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 961b130 commit 679e369

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

branch.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
239239
if (track != BRANCH_TRACK_INHERIT)
240240
for_each_remote(find_tracked_branch, &tracking);
241241
else if (inherit_tracking(&tracking, orig_ref))
242-
return;
242+
goto cleanup;
243243

244244
if (!tracking.matches)
245245
switch (track) {
@@ -249,7 +249,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
249249
case BRANCH_TRACK_INHERIT:
250250
break;
251251
default:
252-
return;
252+
goto cleanup;
253253
}
254254

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

265-
string_list_clear(tracking.srcs, 0);
265+
cleanup:
266+
string_list_clear(&tracking_srcs, 0);
266267
}
267268

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

0 commit comments

Comments
 (0)