On Sat, 8 Aug 2026 16:55:28 GMT, Yunbo Zhang <[email protected]> wrote:

>> 8390024: WB_ParseCommandLine leaks C-heap memory when parsing STRING 
>> arguments
>> 
>> 
>> 
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Yunbo Zhang has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   8390024: Clean up DCmdParser on destruction

Thanks for pointing this out. Further investigation showed that calling 
`cleanup()` from `DCmdParser`'s destructor is not safe in general. `DCmdParser` 
stores non-owning pointers to `GenDCmdArgument` objects. For `DCmdWithParser` 
subclasses, the arguments may be members of the derived class, while 
`_dcmdparser` is a base-class member. The argument objects are therefore 
destroyed first, so the parser destructor could access dangling pointers.

This is consistent with the existing cleanup guidance in 
`diagnosticFramework.hpp`:


// To ensure a proper cleanup, it's highly recommended to use a DCmdMark for
// each diagnostic command instance.


`DCmdMark` calls `cleanup()` while the command and its arguments are still 
alive. `ResourceMark` reclaims Resource Area allocations but does not release 
the C-heap memory owned by parsed argument values.

I therefore reverted the general `DCmdParser` destructor change and restored 
the local scope guard in `WB_ParseCommandLine`. This safely covers both normal 
returns and `CHECK_NULL` early returns. `ParserTest` and the new NMT regression 
test both pass with this implementation.

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

PR Comment: https://git.openjdk.org/jdk/pull/32263#issuecomment-5241792650

Reply via email to