* locale/newlocale.c (__newlocale): Don't leak old data or names.
[glibc.git] / elf / unload2.c
blob7a380534338bca77bf6ac7c253164e45fd2b8b8b
1 #include <dlfcn.h>
2 #include <elf.h>
3 #include <errno.h>
4 #include <error.h>
5 #include <link.h>
6 #include <stdio.h>
7 #include <stdlib.h>
9 #define OUT \
10 for (map = _r_debug.r_map; map != NULL; map = map->l_next) \
11 if (map->l_type == lt_loaded) \
12 printf ("name = \"%s\", opencount = %d\n", \
13 map->l_name, (int) map->l_opencount); \
14 fflush (stdout)
16 int
17 main (void)
19 void *h[3];
20 struct link_map *map;
21 void (*fp) (void);
23 h[0] = dlopen ("unload2mod.so", RTLD_LAZY);
24 h[1] = dlopen ("unload2mod.so", RTLD_LAZY);
25 if (h[0] == NULL || h[1] == NULL)
26 error (EXIT_FAILURE, errno, "cannot load \"unload2mod.so\"");
27 h[2] = dlopen ("unload2dep.so", RTLD_LAZY);
28 if (h[2] == NULL)
29 error (EXIT_FAILURE, errno, "cannot load \"unload2dep.so\"");
31 puts ("\nAfter loading everything:");
32 OUT;
34 dlclose (h[0]);
36 puts ("\nAfter unloading \"unload2mod.so\" once:");
37 OUT;
39 dlclose (h[1]);
41 puts ("\nAfter unloading \"unload2mod.so\" twice:");
42 OUT;
44 fp = dlsym (h[2], "foo");
45 puts ("\nnow calling `foo'");
46 fflush (stdout);
47 fp ();
48 puts ("managed to call `foo'");
49 fflush (stdout);
51 dlclose (h[2]);
53 puts ("\nAfter unloading \"unload2dep.so\":");
54 OUT;
56 return 0;