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

llvm-svn: 322944
This commit is contained in:
Klaus Kretzschmar 2018-01-19 14:17:53 +00:00
parent 3f47fcf102
commit b065dabd10
1 changed files with 6 additions and 1 deletions

View File

@ -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.