Skip to content

Commit d6fa8b0

Browse files
committed
8283469: Don't use memset to initialize members in FileMapInfo and fix memory leak
Reviewed-by: iklam, kbarrett
1 parent 8567266 commit d6fa8b0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/hotspot/share/cds/filemap.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +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(const char* full_path, bool is_static) {
170-
memset((void*)this, 0, sizeof(FileMapInfo));
171-
_full_path = full_path;
172-
_is_static = is_static;
169+
FileMapInfo::FileMapInfo(const char* full_path, bool is_static) :
170+
_is_static(is_static), _file_open(false), _is_mapped(false), _fd(-1), _file_offset(0),
171+
_full_path(full_path), _base_archive_name(nullptr), _header(nullptr) {
173172
if (_is_static) {
174173
assert(_current_info == NULL, "must be singleton"); // not thread safe
175174
_current_info = this;
176175
} else {
177176
assert(_dynamic_archive_info == NULL, "must be singleton"); // not thread safe
178177
_dynamic_archive_info = this;
179178
}
180-
_file_offset = 0;
181-
_file_open = false;
182179
}
183180

184181
FileMapInfo::~FileMapInfo() {
@@ -189,6 +186,11 @@ FileMapInfo::~FileMapInfo() {
189186
assert(_dynamic_archive_info == this, "must be singleton"); // not thread safe
190187
_dynamic_archive_info = NULL;
191188
}
189+
190+
if (_header != nullptr) {
191+
os::free(_header);
192+
}
193+
192194
if (_file_open) {
193195
::close(_fd);
194196
}

0 commit comments

Comments
 (0)