diff --git a/builtin/apply.c b/builtin/apply.c
index dbdfa9b646f..ce3b77853c7 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -4371,8 +4371,10 @@ static int apply_patch(int fd, const char *filename, int options)
 		patch->inaccurate_eof = !!(options & INACCURATE_EOF);
 		patch->recount =  !!(options & RECOUNT);
 		nr = parse_chunk(buf.buf + offset, buf.len - offset, patch);
-		if (nr < 0)
+		if (nr < 0) {
+			free_patch(patch);
 			break;
+		}
 		if (apply_in_reverse)
 			reverse_patches(patch);
 		if (use_patch(patch)) {