Skip to content

Commit 7a6a44c

Browse files
chriscoolgitster
authored andcommitted
builtin/apply: free patch when parse_chunk() fails
When parse_chunk() fails it can return -1, for example when find_header() doesn't find a patch header. In this case it's better in apply_patch() to free the "struct patch" that we just allocated instead of leaking it. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 484e776 commit 7a6a44c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/apply.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4371,8 +4371,10 @@ static int apply_patch(int fd, const char *filename, int options)
43714371
patch->inaccurate_eof = !!(options & INACCURATE_EOF);
43724372
patch->recount = !!(options & RECOUNT);
43734373
nr = parse_chunk(buf.buf + offset, buf.len - offset, patch);
4374-
if (nr < 0)
4374+
if (nr < 0) {
4375+
free_patch(patch);
43754376
break;
4377+
}
43764378
if (apply_in_reverse)
43774379
reverse_patches(patch);
43784380
if (use_patch(patch)) {

0 commit comments

Comments
 (0)