From 71c791605365d1873ef631bfc478fcd75080a063 Mon Sep 17 00:00:00 2001 From: Rubén Justo Date: Tue, 23 Apr 2024 00:54:05 +0200 Subject: apply: plug a leak in apply_data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have an execution path in apply_data that leaks the local struct image. Plug it. This leak can be triggered with: $ echo foo >file $ git add file && git commit -m file $ echo bar >file $ git diff file >diff $ sed s/foo/frotz/ baddiff $ git apply --cached Signed-off-by: Junio C Hamano --- apply.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'apply.c') diff --git a/apply.c b/apply.c index 34f20326a7..2f752d71a8 100644 --- a/apply.c +++ b/apply.c @@ -3712,8 +3712,10 @@ static int apply_data(struct apply_state *state, struct patch *patch, fprintf(stderr, _("Falling back to direct application...\n")); /* Note: with --reject, apply_fragments() returns 0 */ - if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0) + if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0) { + clear_image(&image); return -1; + } } patch->result = image.buf; patch->resultsize = image.len; -- cgit v1.3