aboutsummaryrefslogtreecommitdiff
path: root/lib/asan/lit_tests/malloc_hook.cc
blob: 6435d105ee2685a53f44035844a1b4ca3aafe1ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// RUN: %clangxx_asan -O2 %s -o %t
// RUN: %t 2>&1 | FileCheck %s
#include <stdlib.h>
#include <unistd.h>

extern "C" {
// Note: avoid calling functions that allocate memory in malloc/free
// to avoid infinite recursion.
void __asan_malloc_hook(void *ptr, size_t sz) {
  write(1, "MallocHook\n", sizeof("MallocHook\n"));
}
void __asan_free_hook(void *ptr) {
  write(1, "FreeHook\n", sizeof("FreeHook\n"));
}
}  // extern "C"

int main() {
  volatile int *x = new int;
  // CHECK: MallocHook
  *x = 0;
  delete x;
  // CHECK: FreeHook
  return 0;
}