8180869: Cleaner image file reading handling
Reviewed-by: ahgross, rriggs, rhalade
Contributed-by: james.laskey@oracle.com
--- a/src/java.base/share/native/libjimage/imageFile.cpp Thu Jun 01 15:15:26 2017 -0700
+++ b/src/java.base/share/native/libjimage/imageFile.cpp Mon Jun 05 12:36:15 2017 -0300
@@ -205,12 +205,19 @@
// Manage a table of open image files. This table allows multiple access points
// to share an open image.
ImageFileReaderTable::ImageFileReaderTable() : _count(0), _max(_growth) {
- _table = new ImageFileReader*[_max];
+ _table = static_cast<ImageFileReader**>(calloc(_max, sizeof(ImageFileReader*)));
assert(_table != NULL && "allocation failed");
}
ImageFileReaderTable::~ImageFileReaderTable() {
- delete[] _table;
+ for (u4 i = 0; i < _count; i++) {
+ ImageFileReader* image = _table[i];
+
+ if (image != NULL) {
+ delete image;
+ }
+ }
+ free(_table);
}
// Add a new image entry to the table.
--- a/src/java.base/share/native/libjimage/imageFile.hpp Thu Jun 01 15:15:26 2017 -0700
+++ b/src/java.base/share/native/libjimage/imageFile.hpp Mon Jun 05 12:36:15 2017 -0300
@@ -402,6 +402,7 @@
// 'opened' by reference point and decremented when 'closed'. Use of zero
// leads the ImageFileReader to be actually closed and discarded.
class ImageFileReader {
+friend class ImageFileReaderTable;
private:
// Manage a number of image files such that an image can be shared across
// multiple uses (ex. loader.)