8180869: Cleaner image file reading handling

Reviewed-by: ahgross, rriggs, rhalade
This commit is contained in:
James Laskey 2017-06-05 12:36:15 -03:00 committed by Jim Laskey
parent 3d8ce35924
commit 03e33188f3
2 changed files with 10 additions and 2 deletions

View File

@ -205,12 +205,19 @@ const char* ImageModuleData::package_to_module(const char* package_name) {
// 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.

View File

@ -402,6 +402,7 @@ public:
// '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.)