hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame malloc/tst-tcfree2.c

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