< prev index next >

src/hotspot/share/memory/filemap.cpp

Print this page

        

@@ -1746,10 +1746,18 @@
 }
 
 bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
                                 int max, int* num, bool is_open_archive) {
   MemRegion* regions = MemRegion::create_array(max, mtInternal);
+ 
+  struct Cleanup {
+    MemRegion* _regions;
+    bool _aborted;
+    Cleanup(MemRegion* regions) : _regions(regions), _aborted(true) { }
+    ~Cleanup() { if (_aborted) { FREE_C_HEAP_ARRAY(MemRegion, _regions); } }
+  } cleanup(regions);
+
   FileMapRegion* si;
   int region_num = 0;
 
   for (int i = first;
            i < first + max; i++) {

@@ -1805,10 +1813,11 @@
       log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
       return false;
     }
   }
 
+  cleanup._aborted = false;
   // the shared heap data is mapped successfully
   *heap_mem = regions;
   *num = region_num;
   return true;
 }
< prev index next >