8347758: modules.cpp leaks string returned from get_numbered_property_as_sorted_string()

Reviewed-by: dholmes, iklam, ccheung
This commit is contained in:
Zhengyu Gu 2025-01-20 19:13:59 +00:00
parent 3a4d5ff7a3
commit ca863fd5ab

View File

@ -610,12 +610,14 @@ void Modules::serialize(SerializeClosure* soc) {
}
void Modules::dump_native_access_flag() {
ResourceMark rm;
const char* native_access_names = get_native_access_flags_as_sorted_string();
if (native_access_names != nullptr) {
_archived_native_access_flags = ArchiveBuilder::current()->ro_strdup(native_access_names);
}
}
// Caller needs ResourceMark
const char* Modules::get_native_access_flags_as_sorted_string() {
return get_numbered_property_as_sorted_string("jdk.module.enable.native.access");
}
@ -623,6 +625,7 @@ const char* Modules::get_native_access_flags_as_sorted_string() {
void Modules::serialize_native_access_flags(SerializeClosure* soc) {
soc->do_ptr(&_archived_native_access_flags);
if (soc->reading()) {
ResourceMark rm;
check_archived_flag_consistency(_archived_native_access_flags, get_native_access_flags_as_sorted_string(), "jdk.module.enable.native.access");
// Don't hold onto the pointer, in case we might decide to unmap the archive.
@ -631,12 +634,14 @@ void Modules::serialize_native_access_flags(SerializeClosure* soc) {
}
void Modules::dump_addmods_names() {
ResourceMark rm;
const char* addmods_names = get_addmods_names_as_sorted_string();
if (addmods_names != nullptr) {
_archived_addmods_names = ArchiveBuilder::current()->ro_strdup(addmods_names);
}
}
// Caller needs ResourceMark
const char* Modules::get_addmods_names_as_sorted_string() {
return get_numbered_property_as_sorted_string("jdk.module.addmods");
}
@ -644,6 +649,7 @@ const char* Modules::get_addmods_names_as_sorted_string() {
void Modules::serialize_addmods_names(SerializeClosure* soc) {
soc->do_ptr(&_archived_addmods_names);
if (soc->reading()) {
ResourceMark rm;
check_archived_flag_consistency(_archived_addmods_names, get_addmods_names_as_sorted_string(), "jdk.module.addmods");
// Don't hold onto the pointer, in case we might decide to unmap the archive.
@ -651,8 +657,8 @@ void Modules::serialize_addmods_names(SerializeClosure* soc) {
}
}
// Caller needs ResourceMark
const char* Modules::get_numbered_property_as_sorted_string(const char* property) {
ResourceMark rm;
// theoretical string size limit for decimal int, but the following loop will end much sooner due to
// OS command-line size limit.
const int max_digits = 10;
@ -705,7 +711,7 @@ const char* Modules::get_numbered_property_as_sorted_string(const char* property
}
}
return (st.size() > 0) ? os::strdup(st.as_string()) : nullptr; // Example: "java.base,java.compiler"
return (st.size() > 0) ? st.as_string() : nullptr; // Example: "java.base,java.compiler"
}
void Modules::define_archived_modules(Handle h_platform_loader, Handle h_system_loader, TRAPS) {