RFR (S): 8239070: Memory leak when unsuccessfully mapping in archive regions

Kim Barrett kim.barrett at oracle.com
Sat Feb 15 08:20:38 UTC 2020


> On Feb 14, 2020, at 11:08 AM, Ioi Lam <ioi.lam at oracle.com> wrote:
> 
> Hi Thomas,
> 
> Thanks for fixing this issue. Freeing the array at each exit point seems error prone. How about: refactoring the function to a FileMapInfo::map_heap_data_impl function, allocate inside FileMapInfo::map_heap_data(), call map_heap_data() and if it returns false, free the array in a single place.

Rather than splitting up the function, one could add a local cleanup handler:

  ... create and initialize regions object ...
  struct Cleanup {
    MemRegion* _regions;
    bool _aborted;
    Cleanup(MemRegion* regions) : _regions(regions), _aborted(true) {}
    ~Cleanup() { if (_aborted) FREE_C_HEAP_ARRAY(MemRegion, _regions); }
  } cleanup(regions);
  ...
  cleanup._aborted = false;
  return true;
}

or use std::unique_ptr :(



More information about the hotspot-gc-dev mailing list