Fix race condition in GetPreResolvedStrings
DexCache::VisitReferences had a race condition where a null pointer
could be accessed if there was another concurrent caller doing
ClearPreResolvedStrings.
Fix is to add an extra null check that prevents the race.
Bug: 152716138
Test: test-art-host
Change-Id: Ib447ce689e23f7c20d4cda8b457abeb89ade9291
diff --git a/runtime/mirror/dex_cache-inl.h b/runtime/mirror/dex_cache-inl.h
index 80b5a34..4f23273 100644
--- a/runtime/mirror/dex_cache-inl.h
+++ b/runtime/mirror/dex_cache-inl.h
@@ -382,9 +382,11 @@
}
GcRoot<mirror::String>* const preresolved_strings = GetPreResolvedStrings();
- const size_t num_preresolved_strings = NumPreResolvedStrings();
- for (size_t i = 0; i != num_preresolved_strings; ++i) {
- visitor.VisitRootIfNonNull(preresolved_strings[i].AddressWithoutBarrier());
+ if (preresolved_strings != nullptr) {
+ const size_t num_preresolved_strings = NumPreResolvedStrings();
+ for (size_t i = 0; i != num_preresolved_strings; ++i) {
+ visitor.VisitRootIfNonNull(preresolved_strings[i].AddressWithoutBarrier());
+ }
}
}
}