Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk18u Public archive

Commit 642208c

Browse files
committed
8283469: Don't use memset to initialize members in FileMapInfo and fix memory leak
Reviewed-by: phh Backport-of: d6fa8b004bcd0a2fc1015055d0177428889b4c31
1 parent 2e9dda4 commit 642208c

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
@@ -166,18 +166,16 @@ template <int N> static void get_header_version(char (&header_version) [N]) {
166166
assert(header_version[JVM_IDENT_MAX-1] == 0, "must be");
167167
}
168168

169-
FileMapInfo::FileMapInfo(bool is_static) {
170-
memset((void*)this, 0, sizeof(FileMapInfo));
171-
_is_static = is_static;
169+
FileMapInfo::FileMapInfo(bool is_static) :
170+
_is_static(is_static), _file_open(false), _is_mapped(false), _fd(-1), _file_offset(0),
171+
_full_path(nullptr), _base_archive_name(nullptr), _header(nullptr) {
172172
if (_is_static) {
173173
assert(_current_info == NULL, "must be singleton"); // not thread safe
174174
_current_info = this;
175175
} else {
176176
assert(_dynamic_archive_info == NULL, "must be singleton"); // not thread safe
177177
_dynamic_archive_info = this;
178178
}
179-
_file_offset = 0;
180-
_file_open = false;
181179
}
182180

183181
FileMapInfo::~FileMapInfo() {
@@ -188,6 +186,14 @@ FileMapInfo::~FileMapInfo() {
188186
assert(_dynamic_archive_info == this, "must be singleton"); // not thread safe
189187
_dynamic_archive_info = NULL;
190188
}
189+
190+
if (_header != nullptr) {
191+
os::free(_header);
192+
}
193+
194+
if (_file_open) {
195+
::close(_fd);
196+
}
191197
}
192198

193199
void FileMapInfo::populate_header(size_t core_region_alignment) {

0 commit comments

Comments
 (0)