Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH] builtin/apply: free patch when parse_chunk() fails

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:09:10

Christian Couder [off-list ref] writes:
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 <redacted>
---
 builtin/apply.c | 4 +++-
OK.  Will queue.  Thanks.
quoted hunk
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index 42c610e..bf78282 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -4373,8 +4373,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)) {
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help