8180869: Cleaner image file reading handling
authorjlaskey
Mon, 05 Jun 2017 12:36:15 -0300
changeset 48565 871b8bb201ea
parent 48564 1fc3a5f9791f
child 48566 6c986cf7299a
8180869: Cleaner image file reading handling Reviewed-by: ahgross, rriggs, rhalade Contributed-by: james.laskey@oracle.com
src/java.base/share/native/libjimage/imageFile.cpp
src/java.base/share/native/libjimage/imageFile.hpp
--- 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.)