> …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 incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision: - use NMT Serviceability instead - 8392739: JvmtiEnvBase::set_native_method_prefixes leaks one prefix string on its error paths ------------- Changes: - all: https://git.openjdk.org/jdk/pull/32969/files - new: https://git.openjdk.org/jdk/pull/32969/files/bfad6f15..987e3415 Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=32969&range=01 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=32969&range=00-01 Stats: 130 lines in 43 files changed: 6 ins; 8 del; 116 mod Patch: https://git.openjdk.org/jdk/pull/32969.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/32969/head:pull/32969 PR: https://git.openjdk.org/jdk/pull/32969
