Skip to content

Commit

Permalink
Address review comments 2
Browse files Browse the repository at this point in the history
  • Loading branch information
KostasTsiounis committed Dec 9, 2024
1 parent e815847 commit 6bef143
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions closed/src/java.base/share/native/libjncrypto/NativeCrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,27 +675,32 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath)

/* If JAVA_HOME is not null or empty and no library has been loaded yet, try there. */
if ((NULL != chomepath) && ('\0' != *chomepath) && (NULL == crypto_library)) {
size_t path_len = strlen(chomepath);
#if defined(_WIN32)
static const char pathSuffix[] = "\\bin\\";
#else /* defined(_WIN32) */
static const char pathSuffix[] = "/lib/";
#endif /* defined(_WIN32) */
char *libPath = malloc(path_len + sizeof(pathSuffix));
size_t path_len = strlen(chomepath) + sizeof(pathSuffix) - 1;
char *libPath = malloc(path_len + 1);
if (NULL == libPath) {
if (traceEnabled) {
fprintf(stderr, "\tFailed to allocate memory for path.\n");
}
return NULL;
}
strcpy(libPath, chomepath);

/* Append the proper directory using a slash or backslash, depending on the operating system. */
strcat(libPath, pathSuffix);

size_t libPath_len = strlen(libPath);
if (traceEnabled) {
fprintf(stdout, "Attempting to load library bundled with JDK from: %s\n", libPath);
}

for (i = 0; i < numOfLibs; i++) {
size_t file_len = strlen(libNames[i]);
/* Allocate memory for the new file name with the path. */
char *libNameWithPath = (char *)malloc((libPath_len + file_len));
char *libNameWithPath = (char *)malloc(path_len + file_len + 1);

if (NULL == libNameWithPath) {
if (traceEnabled) {
Expand All @@ -713,9 +718,7 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath)
}
result = load_crypto_library(traceEnabled, libNameWithPath);

if (NULL != libNameWithPath) {
free(libNameWithPath);
}
free(libNameWithPath);

if (NULL == result) {
continue;
Expand Down

0 comments on commit 6bef143

Please sign in to comment.