Blame malloc/tst-tcfree2.c

Packit Bot 4c590a
/* Test that malloc tcache catches double free.
Packit Bot 4c590a
   Copyright (C) 2018 Free Software Foundation, Inc.
Packit Bot 4c590a
   This file is part of the GNU C Library.
Packit Bot 4c590a
Packit Bot 4c590a
   The GNU C Library is free software; you can redistribute it and/or
Packit Bot 4c590a
   modify it under the terms of the GNU Lesser General Public
Packit Bot 4c590a
   License as published by the Free Software Foundation; either
Packit Bot 4c590a
   version 2.1 of the License, or (at your option) any later version.
Packit Bot 4c590a
Packit Bot 4c590a
   The GNU C Library is distributed in the hope that it will be useful,
Packit Bot 4c590a
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 4c590a
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot 4c590a
   Lesser General Public License for more details.
Packit Bot 4c590a
Packit Bot 4c590a
   You should have received a copy of the GNU Lesser General Public
Packit Bot 4c590a
   License along with the GNU C Library; if not, see
Packit Bot 4c590a
   <http://www.gnu.org/licenses/>.  */
Packit Bot 4c590a
Packit Bot 4c590a
#include <errno.h>
Packit Bot 4c590a
#include <error.h>
Packit Bot 4c590a
#include <limits.h>
Packit Bot 4c590a
#include <malloc.h>
Packit Bot 4c590a
#include <stdlib.h>
Packit Bot 4c590a
#include <stdio.h>
Packit Bot 4c590a
#include <sys/signal.h>
Packit Bot 4c590a
Packit Bot 4c590a
static int
Packit Bot 4c590a
do_test (void)
Packit Bot 4c590a
{
Packit Bot 4c590a
  char * volatile ptrs[20];
Packit Bot 4c590a
  int i;
Packit Bot 4c590a
Packit Bot 4c590a
  /* Allocate enough small chunks so that when we free them all, the tcache
Packit Bot 4c590a
     is full, and the first one we freed is at the end of its linked list.  */
Packit Bot 4c590a
#define COUNT 20
Packit Bot 4c590a
  for (i=0; i
Packit Bot 4c590a
    ptrs[i] = malloc (20);
Packit Bot 4c590a
  for (i=0; i
Packit Bot 4c590a
    free (ptrs[i]);
Packit Bot 4c590a
  free (ptrs[0]);
Packit Bot 4c590a
Packit Bot 4c590a
  printf("FAIL: tcache double free\n");
Packit Bot 4c590a
  return 1;
Packit Bot 4c590a
}
Packit Bot 4c590a
Packit Bot 4c590a
#define TEST_FUNCTION do_test
Packit Bot 4c590a
#define EXPECTED_SIGNAL SIGABRT
Packit Bot 4c590a
#include <support/test-driver.c>