8035870: Check jdk/src/windows/native/java/io/WinNTFileSystem_md.c for JNI pending exceptions

NI return checks, NULL return checks for malloc added

Reviewed-by: alanb, chegar
This commit is contained in:
Mark Sheppard 2014-03-21 00:57:23 +00:00
parent 4d1b400d2d
commit f60c942caa
2 changed files with 19 additions and 15 deletions

View File

@ -85,7 +85,7 @@ extern int wcanonicalizeWithPrefix(const WCHAR *canonicalPrefix, const WCHAR *pa
* Retrieves the fully resolved (final) path for the given path or NULL
* if the function fails.
*/
static WCHAR* getFinalPath(const WCHAR *path)
static WCHAR* getFinalPath(JNIEnv *env, const WCHAR *path)
{
HANDLE h;
WCHAR *result;
@ -121,6 +121,7 @@ static WCHAR* getFinalPath(const WCHAR *path)
len = (*GetFinalPathNameByHandle_func)(h, result, len, 0);
} else {
len = 0;
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
}
@ -141,6 +142,7 @@ static WCHAR* getFinalPath(const WCHAR *path)
/* copy result without prefix into new buffer */
WCHAR *tmp = (WCHAR*)malloc(resultLen * sizeof(WCHAR));
if (tmp == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
len = 0;
} else {
WCHAR *p = result;
@ -164,6 +166,8 @@ static WCHAR* getFinalPath(const WCHAR *path)
free(result);
result = NULL;
}
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
error = GetLastError();
@ -257,6 +261,8 @@ Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this,
rv = (*env)->NewString(env, cp, (jsize)wcslen(cp));
}
free(cp);
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
} else if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) {
rv = (*env)->NewString(env, canonicalPath, (jsize)wcslen(canonicalPath));
@ -288,6 +294,8 @@ Java_java_io_WinNTFileSystem_canonicalizeWithPrefix0(JNIEnv *env, jobject this,
rv = (*env)->NewString(env, cp, (jsize)wcslen(cp));
}
free(cp);
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
} else if (wcanonicalizeWithPrefix(canonicalPrefix,
pathWithCanonicalPrefix,
@ -433,7 +441,7 @@ Java_java_io_WinNTFileSystem_setPermission(JNIEnv *env, jobject this,
if ((a != INVALID_FILE_ATTRIBUTES) &&
((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
{
WCHAR *fp = getFinalPath(pathbuf);
WCHAR *fp = getFinalPath(env, pathbuf);
if (fp == NULL) {
a = INVALID_FILE_ATTRIBUTES;
} else {
@ -628,6 +636,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
if (search_path == 0) {
free (pathbuf);
errno = ENOMEM;
JNU_ThrowOutOfMemoryError(env, "native memory allocation faiuled");
return NULL;
}
wcscpy(search_path, pathbuf);
@ -803,7 +812,7 @@ Java_java_io_WinNTFileSystem_setReadOnly(JNIEnv *env, jobject this,
if ((a != INVALID_FILE_ATTRIBUTES) &&
((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
{
WCHAR *fp = getFinalPath(pathbuf);
WCHAR *fp = getFinalPath(env, pathbuf);
if (fp == NULL) {
a = INVALID_FILE_ATTRIBUTES;
} else {

View File

@ -161,10 +161,6 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) {
{
if (pathlen > max_path - 1) {
pathbuf = prefixAbpath(ps, pathlen, pathlen);
if (pathbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL;
}
} else {
pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
if (pathbuf != 0) {
@ -191,10 +187,6 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) {
int dirlen = currentDirLength(ps, pathlen);
if (dirlen + pathlen + 1 > max_path - 1) {
pathbuf = prefixAbpath(ps, pathlen, dirlen + pathlen);
if( pathbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL;
}
} else {
pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
if (pathbuf != 0) {
@ -216,13 +208,16 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) {
return NULL;
} else {
pathbuf = (WCHAR*)malloc(sizeof(WCHAR));
if (pathbuf != NULL) {
pathbuf[0] = L'\0';
} else {
JNU_ThrowOutOfMemoryError(env, 0);
return NULL;
}
}
}
if (pathbuf == 0) {
if (!(*env)->ExceptionCheck(env)) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
JNU_ThrowOutOfMemoryError(env, 0);
return NULL;
}
return pathbuf;