…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). ------------- Commit messages: - 8392739: JvmtiEnvBase::set_native_method_prefixes leaks one prefix string on its error paths Changes: https://git.openjdk.org/jdk/pull/32969/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=32969&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8392739 Stats: 190 lines in 3 files changed: 188 ins; 0 del; 2 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
