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 %libdl -o %t 6// RUN: %env_asan_opts=exitcode=0 %run %t 2>&1 | FileCheck %s 7// XFAIL: arm-linux-gnueabi 8// XFAIL: armv7l-unknown-linux-gnueabihf 9 10#include <assert.h> 11#include <dlfcn.h> 12#include <stdlib.h> 13#include <stdio.h> 14#include <unistd.h> 15 16#include <sanitizer/common_interface_defs.h> 17 18#ifdef SHARED 19extern "C" { 20void *foo() { 21 return malloc(1); 22} 23} 24#else 25void *handle; 26 27int main(int argc, char **argv) { 28 void *handle = dlopen(SO_DIR "/stack_trace_dlclose.so", RTLD_LAZY); 29 assert(handle); 30 void *(*foo)() = (void *(*)())dlsym(handle, "foo"); 31 assert(foo); 32 void *p = foo(); 33 assert(p); 34 dlclose(handle); 35 36 free(p); 37 free(p); // double-free 38 39 return 0; 40} 41#endif 42 43// CHECK: {{ #0 0x.* in (__interceptor_)?malloc}} 44// CHECK: {{ #1 0x.* \(<unknown module>\)}} 45// CHECK: {{ #2 0x.* in main}} 46