8035930: Check jdk/src/windows/native/java/io/io_util_md.c for JNI pending exceptions
authormsheppar
Thu, 20 Mar 2014 23:12:55 +0000
changeset 23561 babc1414a7e4
parent 23560 80b1514e7eac
child 23562 596efd9dfcaf
8035930: Check jdk/src/windows/native/java/io/io_util_md.c for JNI pending exceptions Summary: malloc null return checks and pending exception checks Reviewed-by: alanb
jdk/src/windows/native/java/io/io_util_md.c
--- a/jdk/src/windows/native/java/io/io_util_md.c	Thu Mar 20 22:57:39 2014 +0000
+++ b/jdk/src/windows/native/java/io/io_util_md.c	Thu Mar 20 23:12:55 2014 +0000
@@ -161,10 +161,17 @@
             {
                  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) {
                          wcscpy(pathbuf, ps);
+                     } else {
+                         JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
+                         return NULL;
                      }
                  }
             } else {
@@ -184,10 +191,17 @@
                 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) {
                         wcscpy(pathbuf, ps);
+                    } else {
+                        JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
+                        return NULL;
                     }
                 }
             }
@@ -196,7 +210,9 @@
 
     if (pathlen == 0) {
         if (throwFNFE == JNI_TRUE) {
-            throwFileNotFoundException(env, path);
+            if (!(*env)->ExceptionCheck(env)) {
+                throwFileNotFoundException(env, path);
+            }
             return NULL;
         } else {
             pathbuf = (WCHAR*)malloc(sizeof(WCHAR));
@@ -204,7 +220,9 @@
         }
     }
     if (pathbuf == 0) {
-        JNU_ThrowOutOfMemoryError(env, 0);
+        if (!(*env)->ExceptionCheck(env)) {
+            JNU_ThrowOutOfMemoryError(env,  "native memory allocation failed");
+        }
         return NULL;
     }
     return pathbuf;