zero_realloc_free.c 758 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "test/jemalloc_test.h"
  2. static uint64_t
  3. deallocated() {
  4. if (!config_stats) {
  5. return 0;
  6. }
  7. uint64_t deallocated;
  8. size_t sz = sizeof(deallocated);
  9. expect_d_eq(mallctl("thread.deallocated", (void *)&deallocated, &sz,
  10. NULL, 0), 0, "Unexpected mallctl failure");
  11. return deallocated;
  12. }
  13. TEST_BEGIN(test_realloc_free) {
  14. void *ptr = mallocx(42, 0);
  15. expect_ptr_not_null(ptr, "Unexpected mallocx error");
  16. uint64_t deallocated_before = deallocated();
  17. ptr = realloc(ptr, 0);
  18. uint64_t deallocated_after = deallocated();
  19. expect_ptr_null(ptr, "Realloc didn't free");
  20. if (config_stats) {
  21. expect_u64_gt(deallocated_after, deallocated_before,
  22. "Realloc didn't free");
  23. }
  24. }
  25. TEST_END
  26. int
  27. main(void) {
  28. return test(
  29. test_realloc_free);
  30. }