Skip to content
Permalink
Browse files
8259577: Dangling reference to temp_path in Java_sun_tools_attach_Vir…
…tualMachineImpl_getTempDir

Reviewed-by: cjplummer, lmesnik
  • Loading branch information
Kevin Walls committed Mar 8, 2021
1 parent a0c3f24 commit 51cca57c2254c39955bf160a62810f6a14eff76f
Showing 1 changed file with 8 additions and 11 deletions.
@@ -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
@@ -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__ */

0 comments on commit 51cca57

Please sign in to comment.