diff --git a/elfio/elfio_section.hpp b/elfio/elfio_section.hpp
index 2bc923882eebd7b8272592a62a6ed2cf782769e8..4b8819c397ea7c0a43dbf175ccbb1b0f7dee18a3 100644
--- a/elfio/elfio_section.hpp
+++ b/elfio/elfio_section.hpp
@@ -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 );
diff --git a/elfio/elfio_segment.hpp b/elfio/elfio_segment.hpp
index 4d35a7411621c1ceae58645616d6ac3e5633da24..428e65beb2f6986777583ae49df6a8aa53a66964 100644
--- a/elfio/elfio_segment.hpp
+++ b/elfio/elfio_segment.hpp
@@ -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 );
             }