aboutsummaryrefslogtreecommitdiff
path: root/elf/noload.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@redhat.com>2011-02-25 20:49:48 -0500
committerUlrich Drepper <drepper@gmail.com>2011-02-25 20:49:48 -0500
commit4bff6e0175ed195871f4e01cc4c4c33274b8f6e3 (patch)
treec66f1fa828edf1592d7f73c4200c16ae2996f8b5 /elf/noload.c
parent661b9e2014b3964469198ce7697a1d0d06aa4882 (diff)
downloadglibc-4bff6e0175ed195871f4e01cc4c4c33274b8f6e3.zip
glibc-4bff6e0175ed195871f4e01cc4c4c33274b8f6e3.tar.gz
glibc-4bff6e0175ed195871f4e01cc4c4c33274b8f6e3.tar.bz2
Fix memory leak in dlopen with RTLD_NOLOAD.
Diffstat (limited to 'elf/noload.c')
-rw-r--r--elf/noload.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/elf/noload.c b/elf/noload.c
index 9281ec7..bcc85ef 100644
--- a/elf/noload.c
+++ b/elf/noload.c
@@ -1,20 +1,28 @@
#include <dlfcn.h>
#include <stdio.h>
+#include <mcheck.h>
int
main (void)
{
int result = 0;
+ void *p;
+
+ mtrace ();
/* First try to load an object which is a dependency. This should
succeed. */
- if (dlopen ("testobj1.so", RTLD_LAZY | RTLD_NOLOAD) == NULL)
+ p = dlopen ("testobj1.so", RTLD_LAZY | RTLD_NOLOAD);
+ if (p == NULL)
{
printf ("cannot open \"testobj1.so\": %s\n", dlerror ());
result = 1;
}
else
- puts ("loading \"testobj1.so\" succeeded, OK");
+ {
+ puts ("loading \"testobj1.so\" succeeded, OK");
+ dlclose (p);
+ }
/* Now try loading an object which is not already loaded. */
if (dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) != NULL)
@@ -25,8 +33,6 @@ main (void)
else
{
/* Load the object and run the same test again. */
- void *p;
-
puts ("\"testobj5.so\" wasn't loaded and RTLD_NOLOAD prevented it, OK");
p = dlopen ("testobj5.so", RTLD_LAZY);
@@ -41,13 +47,17 @@ main (void)
{
puts ("loading \"testobj5.so\" succeeded, OK");
- if (dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) == NULL)
+ void *q = dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD);
+ if (q == NULL)
{
printf ("cannot open \"testobj5.so\": %s\n", dlerror ());
result = 1;
}
else
- puts ("loading \"testobj5.so\" with RTLD_NOLOAD succeeded, OK");
+ {
+ puts ("loading \"testobj5.so\" with RTLD_NOLOAD succeeded, OK");
+ dlclose (q);
+ }
if (dlclose (p) != 0)
{