changeset 59930:b0417eb55b11

8239070: Memory leak when unsuccessfully mapping in archive regions Reviewed-by: kbarrett, iklam, coleenp, jiangli
author tschatzl
date Wed, 19 Feb 2020 10:04:54 +0100
parents ba5e9182b08c
children de0fa05b18c7
files src/hotspot/share/memory/filemap.cpp
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/memory/filemap.cpp	Wed Feb 19 09:40:38 2020 +0100
+++ b/src/hotspot/share/memory/filemap.cpp	Wed Feb 19 10:04:54 2020 +0100
@@ -1748,6 +1748,14 @@
 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;
 
@@ -1807,6 +1815,7 @@
     }
   }
 
+  cleanup._aborted = false;
   // the shared heap data is mapped successfully
   *heap_mem = regions;
   *num = region_num;