8207060: Memory leak when malloc fails within WITH_UNICODE_STRING block
Reviewed-by: vtewari, rriggs
--- 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;
}