Blame malloc/tst-tcfree2.c

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