8246308: Reference count for PackageEntry::name may be incorrectly decremented

Corrected the usage of TempNewSymbol.

Reviewed-by: minqi, iklam
This commit is contained in:
Calvin Cheung 2020-07-13 16:05:25 +00:00
parent 097720cce5
commit 5146474954
2 changed files with 12 additions and 2 deletions

View file

@ -717,7 +717,7 @@ Handle SystemDictionaryShared::get_shared_jar_url(int shared_path_index, TRAPS)
Handle SystemDictionaryShared::get_package_name(Symbol* class_name, TRAPS) {
ResourceMark rm(THREAD);
Handle pkgname_string;
Symbol* pkg = ClassLoader::package_from_class_name(class_name);
TempNewSymbol pkg = ClassLoader::package_from_class_name(class_name);
if (pkg != NULL) { // Package prefix found
const char* pkgname = pkg->as_klass_external_name();
pkgname_string = java_lang_String::create_from_str(pkgname,

View file

@ -2825,7 +2825,17 @@ void InstanceKlass::set_package(ClassLoaderData* loader_data, PackageEntry* pkg_
check_prohibited_package(name(), loader_data, CHECK);
}
TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() : ClassLoader::package_from_class_name(name());
// ClassLoader::package_from_class_name has already incremented the refcount of the symbol
// it returns, so we need to decrement it when the current function exits.
TempNewSymbol from_class_name =
(pkg_entry != NULL) ? NULL : ClassLoader::package_from_class_name(name());
Symbol* pkg_name;
if (pkg_entry != NULL) {
pkg_name = pkg_entry->name();
} else {
pkg_name = from_class_name;
}
if (pkg_name != NULL && loader_data != NULL) {