diff options
author | Peter Collingbourne <pcc@google.com> | 2020-09-21 15:26:02 -0700 |
---|---|---|
committer | Steven Moreland <smoreland@google.com> | 2020-09-24 17:01:54 +0000 |
commit | 978eb16cd400c67f756fb572a9c4ef54c758cf7a (patch) | |
tree | d280b5ecd3cbf32d4c35eac3984622ec88f23228 /tests/malloc_test.cpp | |
parent | f15d33e2f9171213b16f6d59a9823cc298295038 (diff) |
Copy the M_THREAD_DISABLE_MEM_INIT constant value into malloc.h.
This will allow platform and application developers to use it.
Bug: 163630045
Change-Id: If9a361cb97aaf62d3fa124b60f64d51d609af48d
Diffstat (limited to 'tests/malloc_test.cpp')
-rw-r--r-- | tests/malloc_test.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp index 55bd1499f..d692cf95c 100644 --- a/tests/malloc_test.cpp +++ b/tests/malloc_test.cpp @@ -84,6 +84,24 @@ TEST(malloc, calloc_std) { free(ptr); } +TEST(malloc, calloc_mem_init_disabled) { +#if defined(__BIONIC__) + // calloc should still zero memory if mem-init is disabled. + // With jemalloc the mallopts will fail but that shouldn't affect the + // execution of the test. + mallopt(M_THREAD_DISABLE_MEM_INIT, 1); + size_t alloc_len = 100; + char *ptr = reinterpret_cast<char*>(calloc(1, alloc_len)); + for (size_t i = 0; i < alloc_len; i++) { + ASSERT_EQ(0, ptr[i]); + } + free(ptr); + mallopt(M_THREAD_DISABLE_MEM_INIT, 0); +#else + GTEST_SKIP() << "bionic-only test"; +#endif +} + TEST(malloc, calloc_illegal) { SKIP_WITH_HWASAN; errno = 0; |