diff mbox series

[v2,4/4] xdiff: handle allocation failure when merging

Message ID 7e705d771b041ae0d455a4296e2955a24e264779.1645006510.git.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit 43ad3af380702d9e304140f259480de59320e587
Headers show
Series xdiff: handle allocation failures | expand

Commit Message

Phillip Wood Feb. 16, 2022, 10:15 a.m. UTC
From: Phillip Wood <phillip.wood@dunelm.org.uk>

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>
---
 xdiff/xmerge.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index d43abe05b95..af40c88a5b3 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -708,13 +708,18 @@  int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
 	    xdl_build_script(&xe2, &xscr2) < 0)
 		goto out;
 
-	status = 0;
 	if (!xscr1) {
 		result->ptr = xdl_malloc(mf2->size);
+		if (!result->ptr)
+			goto out;
+		status = 0;
 		memcpy(result->ptr, mf2->ptr, mf2->size);
 		result->size = mf2->size;
 	} else if (!xscr2) {
 		result->ptr = xdl_malloc(mf1->size);
+		if (!result->ptr)
+			goto out;
+		status = 0;
 		memcpy(result->ptr, mf1->ptr, mf1->size);
 		result->size = mf1->size;
 	} else {