Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / linux / dlclose_leak.c
blob3161b15c17317ba9cb59a7bfbe28452b7e4e0efa
1 /* Test reporting of memory leaks in objects that have been dlopen'ed.
2 * File: dlclose_leak.c */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <dlfcn.h>
7 #include <assert.h>
9 int (*jmp_on_uninit)(void);
10 char* (*alloc_1_byte)(void);
12 int main(int argc, char** argv)
14 int i; for (i = 0; i < 2; ++i)
16 char* memToLeak;
17 char x __attribute__((unused));
18 void* handle = dlopen("./dlclose_leak_so.so", RTLD_NOW);
19 if(!handle) {
20 printf("FAILURE to dlopen dlclose_leak_so.so\n");
21 return EXIT_FAILURE;
23 jmp_on_uninit = dlsym(handle,"jmp_on_uninit");
24 //fprintf(stderr, "jmp_on_uninit: %p\n", jmp_on_uninit);
25 assert(jmp_on_uninit);
26 alloc_1_byte = dlsym(handle,"alloc_1_byte");
27 //fprintf(stderr, "alloc_1_byte: %p\n", alloc_1_byte);
28 assert(alloc_1_byte);
29 (void)jmp_on_uninit();
30 memToLeak = alloc_1_byte();
31 dlclose(handle);
32 x = memToLeak[-1];
34 fprintf(stderr, "done!\n");
35 return (EXIT_SUCCESS);