Avoid SIGABRT due to over allocating during new instance of objects.

This commit is contained in:
Tim Strazzere 2016-04-21 13:22:40 -07:00 committed by Serge Lamikhov-Center
parent 69b6177bd6
commit 812f7299b3
2 changed files with 21 additions and 4 deletions

View File

@ -147,7 +147,11 @@ class section_impl : public section
{
if ( get_type() != SHT_NOBITS ) {
delete [] data;
data = new char[size];
try {
data = new char[size];
} catch (const std::bad_alloc&) {
data_size = 0;
}
if ( 0 != data && 0 != raw_data ) {
data_size = size;
std::copy( raw_data, raw_data + size, data );
@ -174,7 +178,12 @@ class section_impl : public section
}
else {
data_size = 2*( data_size + size);
char* new_data = new char[data_size];
char* new_data;
try {
new_data = new char[data_size];
} catch (const std::bad_alloc&) {
new_data = 0;
}
if ( 0 != new_data ) {
std::copy( data, data + get_size(), new_data );
std::copy( raw_data, raw_data + size, new_data + get_size() );
@ -216,7 +225,11 @@ class section_impl : public section
Elf_Xword size = get_size();
if ( 0 == data && SHT_NULL != get_type() && SHT_NOBITS != get_type() ) {
data = new char[size];
try {
data = new char[size];
} catch (const std::bad_alloc&) {
data_size = 0;
}
if ( 0 != size ) {
stream.seekg( (*convertor)( header.sh_offset ) );
stream.read( data, size );

View File

@ -183,7 +183,11 @@ class segment_impl : public segment
if ( PT_NULL != get_type() && 0 != get_file_size() ) {
stream.seekg( (*convertor)( ph.p_offset ) );
Elf_Xword size = get_file_size();
data = new char[size];
try {
data = new char[size];
} catch (const std::bad_alloc&) {
data = 0;
}
if ( 0 != data ) {
stream.read( data, size );
}