git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 16, 2022, 10:15 UTC
Message-ID
<7e705d771b041ae0d455a4296e2955a24e264779.1645006510.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1140.v2.git.1645006510.gitgitgadget@gmail.com>
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 --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 {
-- 
gitgitgadget
Previous: Phillip Wood via GitGitGadget
Message 18 of 18 in “xdiff: handle allocation failures”
  1. 0/3 xdiff: handle allocation failuresPhillip Wood via GitGitGadget, Feb 9, 2022
  2. 3/3 xdiff: handle allocation failure when mergingPhillip Wood via GitGitGadget, Feb 9, 2022
  3. 2/3 xdiff: refactor a functionPhillip Wood via GitGitGadget, Feb 9, 2022
  4. Junio C HamanoFeb 9, 2022
  5. Junio C HamanoFeb 10, 2022
  6. Phillip WoodFeb 11, 2022
  7. Junio C HamanoFeb 11, 2022
  8. 1/3 xdiff: handle allocation failure in patience diffPhillip Wood via GitGitGadget, Feb 9, 2022
  9. 0/4 xdiff: handle allocation failuresPhillip Wood via GitGitGadget, Feb 16, 2022
  10. 1/4 xdiff: fix a memory leakPhillip Wood via GitGitGadget, Feb 16, 2022
  11. Ævar Arnfjörð BjarmasonFeb 16, 2022
  12. Phillip WoodFeb 16, 2022
  13. Ævar Arnfjörð BjarmasonFeb 16, 2022
  14. Junio C HamanoFeb 16, 2022
  15. Phillip WoodFeb 17, 2022
  16. 2/4 xdiff: handle allocation failure in patience diffPhillip Wood via GitGitGadget, Feb 16, 2022
  17. 3/4 xdiff: refactor a functionPhillip Wood via GitGitGadget, Feb 16, 2022
  18. 4/4 xdiff: handle allocation failure when mergingPhillip Wood via GitGitGadget, Feb 16, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.