Skip to content
Permalink
Browse files

8253948: Memory leak in ImageFileReader

Reviewed-by: alanb
  • Loading branch information
zhengyu123 committed Oct 5, 2020
1 parent 65cab55 commit 81dae70f6792401afd39fcf48fd9ae056d272741
@@ -348,7 +348,8 @@ ImageFileReader* ImageFileReader::id_to_reader(u8 id) {
}

// Constructor intializes to a closed state.
ImageFileReader::ImageFileReader(const char* name, bool big_endian) {
ImageFileReader::ImageFileReader(const char* name, bool big_endian) :
_module_data(NULL) {
// Copy the image file name.
int len = (int) strlen(name) + 1;
_name = new char[len];
@@ -369,6 +370,10 @@ ImageFileReader::~ImageFileReader() {
delete[] _name;
_name = NULL;
}

if (_module_data != NULL) {
delete _module_data;
}
}

// Open image file for read access.
@@ -419,9 +424,9 @@ bool ImageFileReader::open() {
_string_bytes = _index_data + string_bytes_offset;

// Initialize the module data
module_data = new ImageModuleData(this);
_module_data = new ImageModuleData(this);
// Successful open (if memory allocation succeeded).
return module_data != NULL;
return _module_data != NULL;
}

// Close image file.
@@ -436,6 +441,11 @@ void ImageFileReader::close() {
osSupport::close(_fd);
_fd = -1;
}

if (_module_data != NULL) {
delete _module_data;
_module_data = NULL;
}
}

// Read directly from the file.
@@ -568,5 +578,5 @@ void ImageFileReader::get_resource(ImageLocation& location, u1* uncompressed_dat

// Return the ImageModuleData for this image
ImageModuleData * ImageFileReader::get_image_module_data() {
return module_data;
return _module_data;
}
@@ -423,7 +423,7 @@ friend class ImageFileReaderTable;
u4* _offsets_table; // Location offset table
u1* _location_bytes; // Location attributes
u1* _string_bytes; // String table
ImageModuleData *module_data; // The ImageModuleData for this image
ImageModuleData *_module_data; // The ImageModuleData for this image

ImageFileReader(const char* name, bool big_endian);
~ImageFileReader();

1 comment on commit 81dae70

@bridgekeeper

This comment has been minimized.

Copy link

@bridgekeeper bridgekeeper bot commented on 81dae70 Oct 5, 2020

Please sign in to comment.