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