On Sun, 20 Sep 2026 07:03:53 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).

Good catch on the bug.

Your test is going to collide with the NMT changes coming in with 
[JDK-8392409](https://bugs.openjdk.org/browse/JDK-8392409) so I suggest waiting 
for that to get integrated and then merge and rework the test. Thanks

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

Changes requested by dholmes (Reviewer).

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

Reply via email to