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

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

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 9, 2022, 10:59 UTC
Message-ID
<3e935abba1d1ea6cbf10883acf47edcb0162105c.1644404356.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1140.git.1644404356.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 | 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
Previous: Phillip Wood via GitGitGadgetNext: Phillip Wood via GitGitGadget
Message 2 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.