Skip to content

Commit db83b64

Browse files
peffgitster
authored andcommitted
sparse-checkout: clear patterns when init() sees existing sparse file
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4318d3a commit db83b64

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

builtin/sparse-checkout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ static int sparse_checkout_init(int argc, const char **argv, const char *prefix)
472472
/* If we already have a sparse-checkout file, use it. */
473473
if (res >= 0) {
474474
free(sparse_filename);
475+
clear_pattern_list(&pl);
475476
return update_working_directory(NULL);
476477
}
477478

0 commit comments

Comments
 (0)