On Thu, 4 Jun 2026 17:55:36 GMT, Kevin Walls <[email protected]> wrote:

> 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).

It might be better to use `strerror_r()` here. `strerror()` is not thread safe 
before glibc 2.32: https://man7.org/linux/man-pages/man3/strerror.3.html

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

PR Comment: https://git.openjdk.org/jdk/pull/31384#issuecomment-4641948919

Reply via email to