[ This message has been posted at the new Dmalloc forums. Please visit the
following URL and/or subscribe to the forum to see the discussion.
http://dmalloc.com/forums/topic_show.pl?tid=20 ]
Hi All,
Best wishes.
I have one library and a test program. I load library dynamically
using dlopen call from my test program. Inside my library i call
strdup and fopen.
If i compile my code as,
gcc -o test test.o -L/usr/lib -ldmalloc -ldl -lc, then fopen fails if
the file is not exists. (if the file is exists, then fclose fails).
Dmalloc error is:
debug-malloc library: dumping program, fatal error
Error: failed OVER picket-fence magic-number check (err 27)
If i compile my code, as
gcc -o test test.o -L/usr/lib -ldl -lc -ldmalloc, then free(strdup
("hello")) fails.
Dmalloc error is:
debug-malloc library: dumping program, fatal error
Error: pointer is not pointing to heap data space (err 21)
I have the code added below.
I should like compile my code so that i can overcome both the above
mentioned issue.
Your help will be greatly appreciated
Thanks,
Srikumar
test.c
------
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <dmalloc.h>
int main ()
{
void* dll_handle;
int (*my_fns)();
dll_handle = dlopen ("./libtestlib.so", RTLD_NOW | RTLD_GLOBAL);
if (dll_handle == NULL)
{
printf ("Unable to load %s.\n%s", "libtestlib.so", dlerror());
return 0;
}
my_fns = dlsym (dll_handle, "my_fns");
if (my_fns)
my_fns();
dlclose (dll_handle);
return 0;
}
testlib.c
---------
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <dmalloc.h>
int my_fns()
{
FILE * fp;
printf ("my_fns");
fp = fopen ("/etc/sample.cfg", "r");
printf ("after fopen");
if (fp)
fclose (fp);
printf ("after fclose");
free (strdup("hello"));
printf ("after strdup");
return 0;
}
testbuild.sh
------------
#!/bin/bash
DMALLOC_OPTIONS=debug=0x4f47d03,inter=1,log=/usr/dmalloc.logfile
export DMALLOC_OPTIONS
gcc -c -Wall testlib.c -g -DDMALLOC
ld -o libtestlib.so -shared testlib.o
gcc -c -Wall -g -DDMALLOC test.c
#gcc -o test test.o -L/usr/lib -ldmalloc -ldl -lc
gcc -o test test.o -L/usr/lib -ldl -lc -ldmalloc
./test
-END-