]> git.ipfire.org Git - thirdparty/git.git/commitdiff
branch.c: use 'goto cleanup' in setup_tracking() to fix memory leaks
authorGlen Choo <chooglen@google.com>
Sat, 29 Jan 2022 00:04:46 +0000 (16:04 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 4 Feb 2022 16:16:39 +0000 (08:16 -0800)
Signed-off-by: Glen Choo <chooglen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
branch.c

index 70026b3c79e33546467f03a755307635ae83ee1f..47251669e1414e99d5b49debe18e3fe6a21cd902 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -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) {
@@ -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)
@@ -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)