Thread (13 messages) 13 messages, 3 authors, 2022-02-17
STALE1580d
Revisions (2)
  1. v1 current
  2. v2 [diff vs current]

[PATCH 3/3] xdiff: handle allocation failure when merging

From: Phillip Wood via GitGitGadget <hidden>
Date: 2022-02-09 11:58:29
Subsystem: the rest · Maintainer: Linus Torvalds

From: Phillip Wood <redacted>

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 <redacted>
---
 xdiff/xmerge.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 48c5e9e3f35..b9d72f0e9f8 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -711,10 +711,18 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
 	status = 0;
 	if (!xscr1) {
 		result->ptr = xdl_malloc(mf2->size);
+		if (!result->ptr) {
+			status = -1;
+			goto out;
+		}
 		memcpy(result->ptr, mf2->ptr, mf2->size);
 		result->size = mf2->size;
 	} else if (!xscr2) {
 		result->ptr = xdl_malloc(mf1->size);
+		if (!result->ptr) {
+			status = -1;
+			goto out;
+		}
 		memcpy(result->ptr, mf1->ptr, mf1->size);
 		result->size = mf1->size;
 	} else {
-- 
gitgitgadget
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help