]> git.ipfire.org Git - thirdparty/git.git/commitdiff
xdiff: handle allocation failure when merging
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Wed, 16 Feb 2022 10:15:09 +0000 (10:15 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Feb 2022 18:58:16 +0000 (10:58 -0800)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
xdiff/xmerge.c

index d43abe05b95c458a0df6ce35c8b878c454be7a1c..af40c88a5b36fa86386a0cd5dfbe8d6dbe8f7fb7 100644 (file)
@@ -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 {