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:
parent
5172199ef9
commit
b8ff3c4dd2
@ -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);
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user