Prevent using static-allocated pthread keys before creation.

Bug: 19993460

Change-Id: I244dea7f5df3c8384f88aa48d635348fafc9cbaf
This commit is contained in:
Yabin Cui
2015-03-05 20:35:32 -08:00
parent 4bd8f9637d
commit 5ddbb3f936
2 changed files with 31 additions and 6 deletions

View File

@@ -181,6 +181,19 @@ TEST(pthread, pthread_key_dirty) {
ASSERT_EQ(0, pthread_key_delete(key));
}
TEST(pthread, static_pthread_key_used_before_creation) {
#if defined(__BIONIC__)
// See http://b/19625804. The bug is about a static/global pthread key being used before creation.
// So here tests if the static/global default value 0 can be detected as invalid key.
static pthread_key_t key;
ASSERT_EQ(nullptr, pthread_getspecific(key));
ASSERT_EQ(EINVAL, pthread_setspecific(key, nullptr));
ASSERT_EQ(EINVAL, pthread_key_delete(key));
#else
GTEST_LOG_(INFO) << "This test tests bionic pthread key implementation detail.\n";
#endif
}
static void* IdFn(void* arg) {
return arg;
}