RFR: 8303068: Memory leak in DwarfFile::LineNumberProgram::run_line_number_program

David Holmes dholmes at openjdk.org
Mon Feb 27 02:44:03 UTC 2023


On Sun, 26 Feb 2023 10:30:51 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:

>> After allocating:
>> 
>> _state = new (std::nothrow) LineNumberProgramState(_header);
>> 
>> we need to `delete _state` before returning.
>> 
>> Testing: tiers 1-3
>> 
>> Thanks.
>
> #else
>    DWARF_LOG_DEBUG("Address:              Line:    Column:   File:");
>  #endif
> -  _state = new (std::nothrow) LineNumberProgramState(_header);
> +  LineNumberProgramState state{_header};
> +  _state = &state;
>    if (_state == nullptr) {
>      DWARF_LOG_ERROR("Failed to create new LineNumberProgramState object");
>      return false;
> 
> 
> Isn't this equivalent?

I'm going to have to look at this in much more detail. I thought `_state` was just locally used but it isn't. So I can't just delete it in the non-error cases, and probably need to reset to `nullptr` as well. That also prevents using the trick @jdksjolen  suggested with the stack allocated instance.

-------------

PR: https://git.openjdk.org/jdk/pull/12738


More information about the hotspot-dev mailing list