Skip to content

Commit

Permalink
8259577: Dangling reference to temp_path in Java_sun_tools_attach_Vir…
Browse files Browse the repository at this point in the history
…tualMachineImpl_getTempDir

Reviewed-by: cjplummer, lmesnik
  • Loading branch information
kevinjwalls committed Mar 8, 2021
1 parent a0c3f24 commit 51cca57
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/jdk.attach/macosx/native/libattach/VirtualMachineImpl.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -314,17 +314,14 @@ JNIEXPORT jstring JNICALL Java_sun_tools_attach_VirtualMachineImpl_getTempDir(JN
// directory not the java application's temp directory, ala java.io.tmpdir.

#ifdef __APPLE__
// macosx has a secure per-user temporary directory
static char *temp_path = NULL;
char temp_path_storage[PATH_MAX];
if (temp_path == NULL) {
int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, temp_path_storage, PATH_MAX);
if (pathSize == 0 || pathSize > PATH_MAX) {
strlcpy(temp_path_storage, "/tmp", sizeof(temp_path_storage));
}
temp_path = temp_path_storage;
// macosx has a secure per-user temporary directory.
// Don't cache the result as this is only called once.
char path[PATH_MAX];
int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, path, PATH_MAX);
if (pathSize == 0 || pathSize > PATH_MAX) {
strlcpy(path, "/tmp", sizeof(path));
}
return JNU_NewStringPlatform(env, temp_path);
return JNU_NewStringPlatform(env, path);
#else /* __APPLE__ */
return (*env)->NewStringUTF(env, "/tmp");
#endif /* __APPLE__ */
Expand Down

1 comment on commit 51cca57

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.