Skip to content

Commit 521e04e

Browse files
peffgitster
authored andcommitted
sparse-checkout: free pattern list in sparse_checkout_list()
In sparse_checkout_list(), we create a pattern_list that needs to eventually be cleared. We remember to do so in the regular code path, but the cone-mode path does an early return, and forgets to clean up. We could fix the leak by adding a new call to clear_pattern_list(). But we can simplify even further by just skipping the early return, pushing the other code path (which consists now of only one line!) into an else block. That also matches the same cone/non-cone if/else used in some other functions. This fixes 15 leaks found in t1091. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 008f59d commit 521e04e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

builtin/sparse-checkout.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix)
9595
quote_c_style(sl.items[i].string, NULL, stdout, 0);
9696
printf("\n");
9797
}
98-
99-
return 0;
98+
} else {
99+
write_patterns_to_file(stdout, &pl);
100100
}
101101

102-
write_patterns_to_file(stdout, &pl);
103102
clear_pattern_list(&pl);
104103

105104
return 0;

0 commit comments

Comments
 (0)