Search the web
Sign In
New User? Sign Up
dmalloc · Debug Malloc Library (dmalloc) Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
dmalloc vs dlopen & strdup vs fopen   Message List  
Reply | Forward Message #527 of 529 |
[ 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-







Tue Nov 11, 2003 6:11 am

srikumarss
Online Now Online Now
Send Email Send Email

Forward
Message #527 of 529 |
Expand Messages Author Sort by Date

[ 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....
Srikumar
srikumarss
Online Now Send Email
Nov 11, 2003
3:13 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help