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). This pull request has now been integrated. Changeset: 14766469 Author: David Carlier <[email protected]> Committer: Serguei Spitsyn <[email protected]> URL: https://git.openjdk.org/jdk/commit/14766469765199548e0ece003e0fbfabf5843e7e Stats: 190 lines in 3 files changed: 188 ins; 0 del; 2 mod 8392739: JvmtiEnvBase::set_native_method_prefixes leaks one prefix string on its error paths Reviewed-by: dholmes, sspitsyn ------------- PR: https://git.openjdk.org/jdk/pull/32969
