]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sparse-checkout: clear patterns when init() sees existing sparse file
authorJeff King <peff@peff.net>
Tue, 4 Jun 2024 10:13:17 +0000 (06:13 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Jun 2024 17:38:23 +0000 (10:38 -0700)
In sparse_checkout_init(), we first try to load patterns from an
existing file. If we found any, we return immediately, but end up
leaking the patterns we parsed. Fixing this reduces the number of leaks
in t7002 from 9 down to 5.

Note that there are two other exits from the function, but they don't
need the same treatment:

  - if we can't resolve HEAD, we write out a hard-coded sparse file and
    return. But we know the pattern list is empty there, since we didn't
    find any in the on-disk file and we haven't yet added any of our
    own.

  - otherwise, we do populate the list and then tail-call into
    write_patterns_and_update(). But that function frees the
    pattern_list itself, so we don't need to.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/sparse-checkout.c

index 7c17ed238c5d3215b7f0514a05d005bb1f9d6007..923e6ecc0a1968a3a1ecd9d9b7ba2f54810e67eb 100644 (file)
@@ -472,6 +472,7 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix)
        /* If we already have a sparse-checkout file, use it. */
        if (res >= 0) {
                free(sparse_filename);
+               clear_pattern_list(&pl);
                return update_working_directory(NULL);
        }