Skip to content

Commit 43ad3af

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a37b80 commit 43ad3af

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

xdiff/xmerge.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,13 +708,18 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
708708
xdl_build_script(&xe2, &xscr2) < 0)
709709
goto out;
710710

711-
status = 0;
712711
if (!xscr1) {
713712
result->ptr = xdl_malloc(mf2->size);
713+
if (!result->ptr)
714+
goto out;
715+
status = 0;
714716
memcpy(result->ptr, mf2->ptr, mf2->size);
715717
result->size = mf2->size;
716718
} else if (!xscr2) {
717719
result->ptr = xdl_malloc(mf1->size);
720+
if (!result->ptr)
721+
goto out;
722+
status = 0;
718723
memcpy(result->ptr, mf1->ptr, mf1->size);
719724
result->size = mf1->size;
720725
} else {

0 commit comments

Comments
 (0)