[poppler] goo/gmem.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Sep 13 21:17:02 UTC 2021


 goo/gmem.h |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

New commits:
commit 247119e3db4a19d57000f15d350165343b0e9092
Author: Even Rouault <even.rouault at spatialys.com>
Date:   Mon Sep 13 22:52:50 2021 +0200

    greallocn(checkoverflow = true, free_p = true): if memory allocation fails, free the previous pointer to avoid memory leak

diff --git a/goo/gmem.h b/goo/gmem.h
index d104061b..4454a27a 100644
--- a/goo/gmem.h
+++ b/goo/gmem.h
@@ -168,7 +168,13 @@ inline void *greallocn(void *p, int count, int size, bool checkoverflow = false,
         std::abort();
     }
 
-    return grealloc(p, bytes, checkoverflow);
+    if (void *q = grealloc(p, bytes, checkoverflow)) {
+        return q;
+    }
+    if (free_p) {
+        gfree(p);
+    }
+    return nullptr;
 }
 
 inline void *greallocn_checkoverflow(void *p, int count, int size)


More information about the poppler mailing list