Skip to content

Commit 81805e0

Browse files
jesse99brson
authored andcommitted
Check for oom in a few more places
1 parent 0402360 commit 81805e0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/rt/memory_region.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ memory_region::realloc(void *mem, size_t orig_size) {
8787

8888
size_t size = orig_size + HEADER_SIZE;
8989
alloc_header *newMem = (alloc_header *)::realloc(alloc, size);
90+
if (newMem == NULL) {
91+
fprintf(stderr, "memory_region::realloc> Out of memory allocating %ld bytes", size);
92+
abort();
93+
}
9094

9195
# if RUSTRT_TRACK_ALLOCATIONS >= 1
9296
assert(newMem->magic == MAGIC);
@@ -118,6 +122,10 @@ memory_region::malloc(size_t size, const char *tag, bool zero) {
118122
size_t old_size = size;
119123
size += HEADER_SIZE;
120124
alloc_header *mem = (alloc_header *)::malloc(size);
125+
if (mem == NULL) {
126+
fprintf(stderr, "memory_region::malloc> Out of memory allocating %ld bytes", size);
127+
abort();
128+
}
121129

122130
# if RUSTRT_TRACK_ALLOCATIONS >= 1
123131
mem->magic = MAGIC;

0 commit comments

Comments
 (0)