xdiff: handle allocation failure when merging

Other users of xdiff such as libgit2 need to be able to handle allocation failures. These allocation failures were previously ignored. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Feb 16, 2022 at 10:15 UTC 43ad3af380702d9e304140f259480de59320e587
1 file changed +6 -1
xdiff/xmerge.c
+6 -1
@@ -708,13 +708,18 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
708 xdl_build_script(&xe2, &xscr2) < 0)
709 goto out;
710
711 - status = 0;
711 if (!xscr1) {
712 result->ptr = xdl_malloc(mf2->size);
713 + if (!result->ptr)
714 + goto out;
715 + status = 0;
716 memcpy(result->ptr, mf2->ptr, mf2->size);
717 result->size = mf2->size;
718 } else if (!xscr2) {
719 result->ptr = xdl_malloc(mf1->size);
720 + if (!result->ptr)
721 + goto out;
722 + status = 0;
723 memcpy(result->ptr, mf1->ptr, mf1->size);
724 result->size = mf1->size;
725 } else {