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.
This commit is contained in:
Ulrich Drepper 2000-06-10 04:31:24 +00:00
parent 04470dc03e
commit d743ba1e9b
5 changed files with 106 additions and 6 deletions

View file

@ -31,6 +31,17 @@
* 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

View 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

View 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);

58
dlfcn/failtest.c Normal file
View file

@ -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)
{
}

25
dlfcn/failtestmod.c Normal file
View file

@ -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);
}