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

@ -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) {