On Mon, 21 Sep 2026 07:10:00 GMT, David Carlier <[email protected]> wrote:

>> …ring on its error paths
>> 
>> Found while sweeping the JVMTI error paths. 
>> `JvmtiEnvBase::set_native_method_prefixes()`
>> copies the agent's prefixes one at a time with `os::strdup()`, and when it 
>> meets a null
>> entry, or a copy that fails, it frees what it has already copied before 
>> returning. Both
>> cleanup loops stop at `i - 1` while the array is populated up to `i`, so the 
>> prefix copied
>> last is never freed and every rejected call leaks one string. Only 
>> `SetNativeMethodPrefixes`
>> with more than one prefix can get there, since `SetNativeMethodPrefix` 
>> always passes a count
>> of one.
>> 
>> The fix is to run both loops to `i`, which also keeps the case where nothing 
>> has been copied
>> yet correct.
>> 
>> The test has an agent call `SetNativeMethodPrefixes` with a one megabyte 
>> prefix followed by a
>> null entry, and compares the Internal figure NMT reports before and after. 
>> An unfixed VM grows
>> by the full amount of the rejected copies, a fixed one stays flat.
>> 
>> Additional testing:
>> 
>> - [ ] linux-x86_64 fastdebug, serviceability/jvmti
>> - [ ] Regular testing pipelines
>> 
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> David Carlier has updated the pull request with a new target base due to a 
> merge or a rebase. The pull request now contains two commits:
> 
>  - use NMT Serviceability instead
>  - 8392739: JvmtiEnvBase::set_native_method_prefixes leaks one prefix string 
> on its error paths

Marked as reviewed by dholmes (Reviewer).

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

PR Review: https://git.openjdk.org/jdk/pull/32969#pullrequestreview-5314524492

Reply via email to