ImageNativeSubstrate.cpp uses "delete" operator instead of "delete []" when it allocates an array with "new" operator:
http://hg.openjdk.java.net/jdk9/dev/jdk/file/20d991bc9171/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp#l213
...
char* path = new char[size + 1];
if (path == NULL) {
return NULL;
}
memcpy(path, rawBytes, size);
path[size] = '\0';
// Locate resource location data.
ImageLocation location;
bool found = reader->find_location(path, location);
delete path;
...
As far as I know, behavior is undefined in this case. It would be better to use delete[]:
diff -r 20d991bc9171 src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp
--- a/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Mon Dec 28 00:02:06 2015 +0000
+++ b/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Mon Dec 28 19:02:19 2015 -0800
@@ -210,7 +210,7 @@
// Locate resource location data.
ImageLocation location;
bool found = reader->find_location(path, location);
- delete path;
+ delete[] path;
// Resource not found.
if (!found) return NULL;
// Expand stream into array.
See also similarJDK-8140649.
http://hg.openjdk.java.net/jdk9/dev/jdk/file/20d991bc9171/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp#l213
...
char* path = new char[size + 1];
if (path == NULL) {
return NULL;
}
memcpy(path, rawBytes, size);
path[size] = '\0';
// Locate resource location data.
ImageLocation location;
bool found = reader->find_location(path, location);
delete path;
...
As far as I know, behavior is undefined in this case. It would be better to use delete[]:
diff -r 20d991bc9171 src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp
--- a/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Mon Dec 28 00:02:06 2015 +0000
+++ b/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Mon Dec 28 19:02:19 2015 -0800
@@ -210,7 +210,7 @@
// Locate resource location data.
ImageLocation location;
bool found = reader->find_location(path, location);
- delete path;
+ delete[] path;
// Resource not found.
if (!found) return NULL;
// Expand stream into array.
See also similar
- relates to
-
JDK-8140649 imageFile should use delete[] with new[]
-
- Resolved
-