8207060: Memory leak when malloc fails within WITH_UNICODE_STRING block
authorigerasim
Thu, 12 Jul 2018 11:18:01 -0700
changeset 51044 68646e6522ca
parent 51043 6c449bdee4fa
child 51045 215d1a5b097a
8207060: Memory leak when malloc fails within WITH_UNICODE_STRING block Reviewed-by: vtewari, rriggs
src/java.base/windows/native/libjava/io_util_md.c
--- a/src/java.base/windows/native/libjava/io_util_md.c	Thu Jul 12 06:04:57 2018 -0700
+++ b/src/java.base/windows/native/libjava/io_util_md.c	Thu Jul 12 11:18:01 2018 -0700
@@ -165,9 +165,6 @@
                      pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
                      if (pathbuf != 0) {
                          wcscpy(pathbuf, ps);
-                     } else {
-                         JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
-                         return NULL;
                      }
                  }
             } else {
@@ -191,9 +188,6 @@
                     pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
                     if (pathbuf != 0) {
                         wcscpy(pathbuf, ps);
-                    } else {
-                        JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
-                        return NULL;
                     }
                 }
             }
@@ -210,15 +204,11 @@
             pathbuf = (WCHAR*)malloc(sizeof(WCHAR));
             if (pathbuf != NULL) {
                 pathbuf[0] = L'\0';
-            } else {
-                JNU_ThrowOutOfMemoryError(env, 0);
-                return NULL;
             }
         }
     }
     if (pathbuf == 0) {
-        JNU_ThrowOutOfMemoryError(env, 0);
-        return NULL;
+        JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
     }
     return pathbuf;
 }