brintos

brintos / llvm-project-archived public Read only

0
0
Text · 758 B · e1f3319 Raw
37 lines · c
1// Test that initially callocked memory is properly freed2// (see https://github.com/google/sanitizers/issues/626).3// 4// RUN: %clang %s -o %t5// RUN: env LD_PRELOAD=%shared_libasan %run %t6//7// REQUIRES: asan-dynamic-runtime8//9// This way of setting LD_PRELOAD does not work with Android test runner.10// REQUIRES: !android11 12#include <stdio.h>13#include <stdlib.h>14 15static void *ptr;16 17// This constructor will run before __asan_init18// so calloc will allocate memory from special pool.19static void init() {20  ptr = calloc(10, 1);21}22 23__attribute__((section(".preinit_array"), used))24void *dummy = init;25 26void free_memory() {27  // This used to abort because28  // Asan's free didn't recognize ptr.29  free(ptr);30}31 32int main() {33  free_memory();34  return 0;35}36 37