8283469: Don't use memset to initialize members in FileMapInfo and fix memory leak

Reviewed-by: phh
Backport-of: d6fa8b004bcd0a2fc1015055d0177428889b4c31
This commit is contained in:
Zhengyu Gu 2022-05-16 12:53:15 +00:00
parent 2e9dda4ac0
commit 642208c378

View File

@ -166,9 +166,9 @@ template <int N> static void get_header_version(char (&header_version) [N]) {
assert(header_version[JVM_IDENT_MAX-1] == 0, "must be");
}
FileMapInfo::FileMapInfo(bool is_static) {
memset((void*)this, 0, sizeof(FileMapInfo));
_is_static = is_static;
FileMapInfo::FileMapInfo(bool is_static) :
_is_static(is_static), _file_open(false), _is_mapped(false), _fd(-1), _file_offset(0),
_full_path(nullptr), _base_archive_name(nullptr), _header(nullptr) {
if (_is_static) {
assert(_current_info == NULL, "must be singleton"); // not thread safe
_current_info = this;
@ -176,8 +176,6 @@ FileMapInfo::FileMapInfo(bool is_static) {
assert(_dynamic_archive_info == NULL, "must be singleton"); // not thread safe
_dynamic_archive_info = this;
}
_file_offset = 0;
_file_open = false;
}
FileMapInfo::~FileMapInfo() {
@ -188,6 +186,14 @@ FileMapInfo::~FileMapInfo() {
assert(_dynamic_archive_info == this, "must be singleton"); // not thread safe
_dynamic_archive_info = NULL;
}
if (_header != nullptr) {
os::free(_header);
}
if (_file_open) {
::close(_fd);
}
}
void FileMapInfo::populate_header(size_t core_region_alignment) {