1 #include "test/jemalloc_test.h" 2 3 #ifdef JEMALLOC_FILL 4 const char *malloc_conf = 5 "abort:false,junk:false,zero:true,redzone:false,quarantine:0"; 6 #endif 7 8 static void 9 test_zero(size_t sz_min, size_t sz_max) 10 { 11 uint8_t *s; 12 size_t sz_prev, sz, i; 13 #define MAGIC ((uint8_t)0x61) 14 15 sz_prev = 0; 16 s = (uint8_t *)mallocx(sz_min, 0); 17 assert_ptr_not_null((void *)s, "Unexpected mallocx() failure"); 18 19 for (sz = sallocx(s, 0); sz <= sz_max; 20 sz_prev = sz, sz = sallocx(s, 0)) { 21 if (sz_prev > 0) { 22 assert_u_eq(s[0], MAGIC, 23 "Previously allocated byte %zu/%zu is corrupted", 24 ZU(0), sz_prev); 25 assert_u_eq(s[sz_prev-1], MAGIC, 26 "Previously allocated byte %zu/%zu is corrupted", 27 sz_prev-1, sz_prev); 28 } 29 30 for (i = sz_prev; i < sz; i++) { 31 assert_u_eq(s[i], 0x0, 32 "Newly allocated byte %zu/%zu isn't zero-filled", 33 i, sz); 34 s[i] = MAGIC; 35 } 36 37 if (xallocx(s, sz+1, 0, 0) == sz) { 38 s = (uint8_t *)rallocx(s, sz+1, 0); 39 assert_ptr_not_null((void *)s, 40 "Unexpected rallocx() failure"); 41 } 42 } 43 44 dallocx(s, 0); 45 #undef MAGIC 46 } 47 48 TEST_BEGIN(test_zero_small) 49 { 50 51 test_skip_if(!config_fill); 52 test_zero(1, SMALL_MAXCLASS-1); 53 } 54 TEST_END 55 56 TEST_BEGIN(test_zero_large) 57 { 58 59 test_skip_if(!config_fill); 60 test_zero(SMALL_MAXCLASS+1, large_maxclass); 61 } 62 TEST_END 63 64 TEST_BEGIN(test_zero_huge) 65 { 66 67 test_skip_if(!config_fill); 68 test_zero(large_maxclass+1, chunksize*2); 69 } 70 TEST_END 71 72 int 73 main(void) 74 { 75 76 return (test( 77 test_zero_small, 78 test_zero_large, 79 test_zero_huge)); 80 } 81