changeset 51705:68646e6522ca

8207060: Memory leak when malloc fails within WITH_UNICODE_STRING block Reviewed-by: vtewari, rriggs
author igerasim
date Thu, 12 Jul 2018 11:18:01 -0700
parents 6c449bdee4fa
children 215d1a5b097a
files src/java.base/windows/native/libjava/io_util_md.c
diffstat 1 files changed, 1 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }