1 | #include <stdio.h> |
2 | #include <dlfcn.h> |
3 | #include <mcheck.h> |
4 | #include <stdlib.h> |
5 | |
6 | static int |
7 | do_test (void) |
8 | { |
9 | void *h; |
10 | int ret = 0; |
11 | /* Carry out *one* failing call to dlopen before starting mtrace to |
12 | force any one-time inintialization that may happen to the |
13 | executable link map e.g. expansion and caching of $ORIGIN. */ |
14 | h = dlopen (file: "$ORIGIN/tst-leaks1.o" , RTLD_LAZY); |
15 | if (h != NULL) |
16 | { |
17 | puts (s: "dlopen unexpectedly succeeded" ); |
18 | ret = 1; |
19 | dlclose (handle: h); |
20 | } |
21 | |
22 | /* Start tracing and run each test 5 times to see if there are any |
23 | leaks in the failing dlopen. */ |
24 | mtrace (); |
25 | |
26 | for (int i = 0; i < 10; i++) |
27 | { |
28 | h = dlopen (file: i < 5 |
29 | ? "./tst-leaks1.c" |
30 | : "$ORIGIN/tst-leaks1.o" , RTLD_LAZY); |
31 | if (h != NULL) |
32 | { |
33 | puts (s: "dlopen unexpectedly succeeded" ); |
34 | ret = 1; |
35 | dlclose (handle: h); |
36 | } |
37 | } |
38 | |
39 | return ret; |
40 | } |
41 | |
42 | #include <support/test-driver.c> |
43 | |