[PATCH 3/3] xdiff: handle allocation failure when merging
- From
- Phillip 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