Skip to content

Commit 0355888

Browse files
committed
8283469: Don't use memset to initialize members in FileMapInfo and fix memory leak
Reviewed-by: mdoerr Backport-of: d6fa8b004bcd0a2fc1015055d0177428889b4c31
1 parent ab81cd0 commit 0355888

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/hotspot/share/cds/filemap.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ template <int N> static void get_header_version(char (&header_version) [N]) {
165165
assert(header_version[JVM_IDENT_MAX-1] == 0, "must be");
166166
}
167167

168-
FileMapInfo::FileMapInfo(bool is_static) {
169-
memset((void*)this, 0, sizeof(FileMapInfo));
170-
_is_static = is_static;
168+
FileMapInfo::FileMapInfo(bool is_static) :
169+
_is_static(is_static), _file_open(false), _is_mapped(false), _fd(-1), _file_offset(0),
170+
_full_path(nullptr), _base_archive_name(nullptr), _header(nullptr) {
171171
size_t header_size;
172172
if (is_static) {
173173
assert(_current_info == NULL, "must be singleton"); // not thread safe
@@ -183,8 +183,6 @@ FileMapInfo::FileMapInfo(bool is_static) {
183183
_header->set_header_size(header_size);
184184
_header->set_version(INVALID_CDS_ARCHIVE_VERSION);
185185
_header->set_has_platform_or_app_classes(true);
186-
_file_offset = 0;
187-
_file_open = false;
188186
}
189187

190188
FileMapInfo::~FileMapInfo() {
@@ -195,6 +193,14 @@ FileMapInfo::~FileMapInfo() {
195193
assert(_dynamic_archive_info == this, "must be singleton"); // not thread safe
196194
_dynamic_archive_info = NULL;
197195
}
196+
197+
if (_header != nullptr) {
198+
os::free(_header);
199+
}
200+
201+
if (_file_open) {
202+
::close(_fd);
203+
}
198204
}
199205

200206
void FileMapInfo::populate_header(size_t core_region_alignment) {

0 commit comments

Comments
 (0)