Native Attach API code e.g.
src/jdk.attach/linux/native/libattach/VirtualMachineImpl.c
uses strdup before calling JNU_ThrowIOException
char* msg = strdup(strerror(res));
JNU_ThrowIOException(env, msg);
if (msg != NULL) {
free(msg);
}
This gets passed along and into e.g. java_lang_String::create_from_str(message,
thread)
which creates a new String object, into which the bytes are copied, so this
strdup/malloc and free are unnecessary.
We do this twice in this file, and in macos and aix versions. I've changed
Linux and MacOs here. The same thing is done in AIX but I have left unchanged
as I don't build/test it. Can update that also if I see any confirmation it's
OK.
---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK
Interim AI Policy](https://openjdk.org/legal/ai).
-------------
Commit messages:
- 8385963: Native Attach API code has unnecessary 'strdup' calls
Changes: https://git.openjdk.org/jdk/pull/31384/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=31384&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8385963
Stats: 22 lines in 2 files changed: 0 ins; 16 del; 6 mod
Patch: https://git.openjdk.org/jdk/pull/31384.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/31384/head:pull/31384
PR: https://git.openjdk.org/jdk/pull/31384