8217291: Failure of ::realloc() should be handled correctly in adlc/forms.cpp

Handle reallocation failures in adlc.

Reviewed-by: kvn, neliasso
This commit is contained in:
Tobias Hartmann 2019-01-22 08:50:49 +01:00
parent 5172199ef9
commit b8ff3c4dd2
3 changed files with 14 additions and 1 deletions

View File

@ -34,6 +34,16 @@ void* AllocateHeap(size_t size) {
return ptr;
}
void* ReAllocateHeap(void* old_ptr, size_t size) {
unsigned char* ptr = (unsigned char*) realloc(old_ptr, size);
if (ptr == NULL && size != 0) {
fprintf(stderr, "Error: Out of memory in ADLC\n"); // logging can cause crash!
fflush(stderr);
exit(1);
}
return ptr;
}
void* Chunk::operator new(size_t requested_size, size_t length) throw() {
return CHeapObj::operator new(requested_size + length);
}

View File

@ -26,6 +26,7 @@
#define SHARE_ADLC_ARENA_HPP
void* AllocateHeap(size_t size);
void* ReAllocateHeap(void* old_ptr, size_t size);
// All classes in adlc may be derived
// from one of the following allocation classes:

View File

@ -48,7 +48,9 @@ NameList::~NameList() {
}
void NameList::addName(const char *name) {
if (_cur == _max) _names =(const char**)realloc(_names,(_max *=2)*sizeof(char*));
if (_cur == _max) {
_names = (const char**) ReAllocateHeap(_names, (_max *=2)*sizeof(char*));
}
_names[_cur++] = name;
}