Skip to content

Commit

Permalink
[Support] - Check nullptr after allocation with malloc in MallocAlloc…
Browse files Browse the repository at this point in the history
…ator - Differential Revision: http://reviews.llvm.org/D34753

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322944 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kkretzsch committed Jan 19, 2018
1 parent bfe367d commit 2975ccf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/llvm/Support/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -94,7 +95,11 @@ class MallocAllocator : public AllocatorBase<MallocAllocator> {

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.
Expand Down

0 comments on commit 2975ccf

Please sign in to comment.