tst-tcfree2.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Test that malloc tcache catches double free.
  2. Copyright (C) 2018-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <error.h>
  17. #include <limits.h>
  18. #include <malloc.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <sys/signal.h>
  22. static int
  23. do_test (void)
  24. {
  25. char * volatile ptrs[20];
  26. int i;
  27. /* Allocate enough small chunks so that when we free them all, the tcache
  28. is full, and the first one we freed is at the end of its linked list. */
  29. #define COUNT 20
  30. for (i=0; i<COUNT; i++)
  31. ptrs[i] = malloc (20);
  32. for (i=0; i<COUNT; i++)
  33. free (ptrs[i]);
  34. free (ptrs[0]);
  35. printf("FAIL: tcache double free\n");
  36. return 1;
  37. }
  38. #define TEST_FUNCTION do_test
  39. #define EXPECTED_SIGNAL SIGABRT
  40. #include <support/test-driver.c>