summaryrefslogtreecommitdiff
path: root/builtin/apply.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2016-03-16 19:35:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-04-01 17:21:55 (GMT)
commit7a6a44c2dc7a59ef8e117c2f1ea3c06ce6a6ff1f (patch)
treeb90e5bee15576156d8a7ca926255bbdb78790ba7 /builtin/apply.c
parent484e77615872b2a62775a6a2dcb1cad0f529c5d3 (diff)
downloadgit-7a6a44c2dc7a59ef8e117c2f1ea3c06ce6a6ff1f.zip
git-7a6a44c2dc7a59ef8e117c2f1ea3c06ce6a6ff1f.tar.gz
git-7a6a44c2dc7a59ef8e117c2f1ea3c06ce6a6ff1f.tar.bz2
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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/apply.c')
-rw-r--r--builtin/apply.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index dbdfa9b..ce3b778 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)) {