[llvm] r322944 - [Support] - Check nullptr after allocation with malloc in MallocAllocator - Differential Revision: http://reviews.llvm.org/D34753

Klaus Kretzschmar via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 06:17:53 PST 2018


Author: kkretzschmar
Date: Fri Jan 19 06:17:53 2018
New Revision: 322944

URL: http://llvm.org/viewvc/llvm-project?rev=322944&view=rev
Log:
[Support] - Check nullptr after allocation with malloc in MallocAllocator - Differential Revision: http://reviews.llvm.org/D34753

Modified:
    llvm/trunk/include/llvm/Support/Allocator.h

Modified: llvm/trunk/include/llvm/Support/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Allocator.h?rev=322944&r1=322943&r2=322944&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Allocator.h (original)
+++ llvm/trunk/include/llvm/Support/Allocator.h Fri Jan 19 06:17:53 2018
@@ -24,6 +24,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/ErrorHandling.h"
 #include <algorithm>
 #include <cassert>
 #include <cstddef>
@@ -94,7 +95,11 @@ public:
 
   LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size,
                                                 size_t /*Alignment*/) {
-    return malloc(Size);
+    void* memPtr =  malloc(Size);
+    if (memPtr == nullptr) 
+      report_bad_alloc_error("Allocation in MallocAllocator failed.");
+
+    return memPtr;
   }
 
   // Pull in base class overloads.




More information about the llvm-commits mailing list