Skip to content

Commit c332464

Browse files
peffgitster
authored andcommitted
sparse-checkout: reuse --stdin buffer when reading patterns
When we read patterns from --stdin, we loop on strbuf_getline(), and detach each line we read to pass into add_pattern(). This used to be necessary because add_pattern() required that the pattern strings remain valid while the pattern_list was in use. But it also created a leak, since we didn't record the detached buffers anywhere else. Now that add_pattern() has been modified to make its own copy of the strings, we can stop detaching and fix the leak. This fixes 4 leaks detected in t1091. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eed1fbe commit c332464

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

builtin/sparse-checkout.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,10 @@ static void add_patterns_from_input(struct pattern_list *pl,
585585
if (file) {
586586
struct strbuf line = STRBUF_INIT;
587587

588-
while (!strbuf_getline(&line, file)) {
589-
size_t len;
590-
char *buf = strbuf_detach(&line, &len);
591-
add_pattern(buf, empty_base, 0, pl, 0);
592-
}
588+
while (!strbuf_getline(&line, file))
589+
add_pattern(line.buf, empty_base, 0, pl, 0);
590+
591+
strbuf_release(&line);
593592
} else {
594593
for (i = 0; i < argc; i++)
595594
add_pattern(argv[i], empty_base, 0, pl, 0);

0 commit comments

Comments
 (0)