Update.
authorUlrich Drepper <drepper@redhat.com>
Sat, 10 Jun 2000 04:31:24 +0000 (04:31 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sat, 10 Jun 2000 04:31:24 +0000 (04:31 +0000)
2000-06-09  H.J. Lu  <hjl@gnu.org>

* dlfcn/dlerror.c (_dlerror_run): Set result->errstring to NULL
after freeing it.

* dlfcn/Makefile (distribute): Add failtestmod.c.
(tests): Add failtest.
Add rules to build and run failtest.
* dlfcn/failtest.c: New file.
* dlfcn/failtestmod.c: New file.

ChangeLog
dlfcn/Makefile
dlfcn/dlerror.c
dlfcn/failtest.c [new file with mode: 0644]
dlfcn/failtestmod.c [new file with mode: 0644]

index e41d9a4..0f738ec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        * elf/dl-reloc.c: Likewise.
        * elf/dl-version.c: Likewise.
 
+2000-06-09  H.J. Lu  <hjl@gnu.org>
+
+       * dlfcn/dlerror.c (_dlerror_run): Set result->errstring to NULL
+       after freeing it.
+
+       * dlfcn/Makefile (distribute): Add failtestmod.c.
+       (tests): Add failtest.
+       Add rules to build and run failtest.
+       * dlfcn/failtest.c: New file.
+       * dlfcn/failtestmod.c: New file.
+
 2000-06-09  David Mosberger-Tang  <davidm@hpl.hp.com>
 
        * sysdeps/unix/sysv/linux/ia64/__longjmp.S: new file
index d14d382..ed72563 100644 (file)
@@ -20,7 +20,7 @@ subdir                := dlfcn
 headers                := bits/dlfcn.h dlfcn.h
 extra-libs     := libdl
 libdl-routines := dlopen dlclose dlsym dlvsym dlerror dladdr
-distribute     := dlopenold.c glreflib1.c glreflib2.c
+distribute     := dlopenold.c glreflib1.c glreflib2.c failtestmod.c
 
 extra-libs-others := libdl
 
@@ -32,9 +32,9 @@ libdl-shared-only-routines := dlopenold
 endif
 
 ifeq (yes,$(build-shared))
-tests = glrefmain
+tests = glrefmain failtest
 endif
-modules-names = glreflib1 glreflib2
+modules-names = glreflib1 glreflib2 failtestmod
 extra-objs += $(modules-names:=.os)
 
 include ../Rules
@@ -46,3 +46,6 @@ $(test-modules): $(objpfx)%.so: $(objpfx)%.os
 $(objpfx)glrefmain: $(objpfx)libdl.so
 $(objpfx)glrefmain.out: $(objpfx)glrefmain \
                        $(objpfx)glreflib1.so $(objpfx)glreflib2.so
+
+$(objpfx)failtest: $(libdl)
+$(objpfx)failtest.out: $(objpfx)failtestmod.so
index 972a9ac..34ea829 100644 (file)
@@ -120,9 +120,12 @@ _dlerror_run (void (*operate) (void *), void *args)
     }
 
   if (result->errstring != NULL)
-    /* Free the error string from the last failed command.  This can
-       happen if `dlerror' was not run after an error was found.  */
-    free ((char *) result->errstring);
+    {
+      /* Free the error string from the last failed command.  This can
+        happen if `dlerror' was not run after an error was found.  */
+      free ((char *) result->errstring);
+      result->errstring = NULL;
+    }
 
   result->errcode = _dl_catch_error (&result->objname, &result->errstring,
                                     operate, args);
diff --git a/dlfcn/failtest.c b/dlfcn/failtest.c
new file mode 100644 (file)
index 0000000..50bbf10
--- /dev/null
@@ -0,0 +1,58 @@
+#include <dlfcn.h>
+#include <stdio.h>
+
+
+/* Number of rounds we perform the test.  */
+#define TEST_ROUNDS    10
+
+
+static const char unknown[] = "a-file-with-this-name-does-not-exist";
+static const char exists[] = "failtestmod.so";
+
+
+int
+main (void)
+{
+  int i;
+
+  setvbuf (stdout, NULL, _IONBF, 0);
+
+  for (i = 0; i < TEST_ROUNDS; ++i)
+    {
+      void *dsc;
+
+      printf ("Round %d: Try loading \"%s\"\n", i, unknown);
+
+      dsc = dlopen (unknown, RTLD_NOW);
+      if (dsc != NULL)
+       {
+         printf ("We found a file of name \"%s\": this should not happen\n",
+                 unknown);
+         return 1;
+       }
+
+      printf ("Round %d: loading \"%s\" failed\n", i, unknown);
+
+      /* Don't use `dlerror', just load an existing file.  */
+      dsc = dlopen (exists, RTLD_NOW);
+      if (dsc == NULL)
+       {
+         printf ("Could not load \"%s\": %s\n", exists, dlerror ());
+         return 1;
+       }
+
+      printf ("Round %d: Loaded \"%s\"\n", i, exists);
+
+      dlclose (dsc);
+
+      printf ("Round %d: Unloaded \"%s\"\n", i, exists);
+    }
+
+  return 0;
+}
+
+
+void
+foo (void)
+{
+}
diff --git a/dlfcn/failtestmod.c b/dlfcn/failtestmod.c
new file mode 100644 (file)
index 0000000..595da4d
--- /dev/null
@@ -0,0 +1,25 @@
+#include <dlfcn.h>
+#include <stdio.h>
+
+
+void
+__attribute__ ((__constructor__))
+constr (void)
+{
+  void *handle;
+  void *m;
+
+  /* Open the library.  */
+  handle = dlopen (NULL, RTLD_NOW);
+  if (handle == NULL)
+    {
+      puts ("Cannot get handle to own object");
+      return;
+    }
+
+  /* Get a symbol.  */
+  m = dlsym (handle, "main");
+  puts ("called dlsym() to get main");
+
+  dlclose (handle);
+}