47 lines · cpp
1// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=3162// XFAIL: android3//4// RUN: rm -rf %t-dir5// RUN: mkdir -p %t-dir6// RUN: %clangxx_asan -DSHARED %s -shared -o %t-dir/stack_trace_dlclose.so -fPIC7// RUN: %clangxx_asan -DSO_DIR=\"%t-dir\" %s %libdl -o %t8// RUN: %env_asan_opts=exitcode=0 %run %t 2>&1 | FileCheck %s9// REQUIRES: stable-runtime10 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 SHARED20extern "C" {21void *foo() {22 return malloc(1);23}24}25#else26void *handle;27 28int 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-free39 40 return 0;41}42#endif43 44// CHECK: {{ #0 0x.* in (__interceptor_)?malloc}}45// CHECK: {{ #1 0x.* \(<unknown module>\)}}46// CHECK: {{ #2 0x.* in main}}47