hjl / source-git / glibc

Forked from source-git/glibc 4 years ago
Clone

Blame malloc/tst-tcfree1.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
  /* Do one allocation of any size that fits in tcache.  */
Packit 090509
  char * volatile x = malloc (32);
Packit 090509
Packit 090509
  free (x); // puts in tcache
Packit 090509
  free (x); // should abort
Packit 090509
Packit 090509
  printf("FAIL: tcache double free not detected\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>