• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2 // XFAIL: android
3 //
4 // RUN: rm -rf %t-dir
5 // RUN: mkdir -p %t-dir
6 // RUN: %clangxx_asan -DSHARED %s -shared -o %t-dir/stack_trace_dlclose.so -fPIC
7 // RUN: %clangxx_asan -DSO_DIR=\"%t-dir\" %s %libdl -o %t
8 // RUN: %env_asan_opts=exitcode=0 %run %t 2>&1 | FileCheck %s
9 // REQUIRES: stable-runtime
10 
11 #include <assert.h>
12 #include <dlfcn.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <unistd.h>
16 
17 #include <sanitizer/common_interface_defs.h>
18 
19 #ifdef SHARED
20 extern "C" {
foo()21 void *foo() {
22   return malloc(1);
23 }
24 }
25 #else
26 void *handle;
27 
main(int argc,char ** argv)28 int main(int argc, char **argv) {
29   void *handle = dlopen(SO_DIR "/stack_trace_dlclose.so", RTLD_LAZY);
30   assert(handle);
31   void *(*foo)() = (void *(*)())dlsym(handle, "foo");
32   assert(foo);
33   void *p = foo();
34   assert(p);
35   dlclose(handle);
36 
37   free(p);
38   free(p);  // double-free
39 
40   return 0;
41 }
42 #endif
43 
44 // CHECK: {{    #0 0x.* in (__interceptor_)?malloc}}
45 // CHECK: {{    #1 0x.* \(<unknown module>\)}}
46 // CHECK: {{    #2 0x.* in main}}
47