signal 10 in malloc call???
John F. Haugh II
jfh at rpp386.UUCP
Tue May 10 11:21:32 AEST 1988
In article <2149 at quacky.mips.COM> dce at mips.COM (David Elliott) writes:
>In article <4016 at killer.UUCP> toma at killer.UUCP (Tom Armistead) writes:
>>He told me to use the special malloc(3X) library with
>>'-lmalloc' on the cc command line. I did this and the problem has gone
>>away!!! "Thank you Antie Em, I'm not CRAZY!!!"
>
>I hate to burst your bubble, Tom, but this doesn't really show that the
>standard libc malloc() is broken.
[ and later he goes to say it also doesn't prove you don't have a bug in
your code. ]
below is some code i use to check the consistency of mallocs in a large
database i am working on. it checks the number of malloc/free pairs, and
the leading edge for consistency. this code is copyright john f. haugh ii,
1987, 1988, all rights reserved (by the way ;-) [ and for the `but your
code has X problem' people - it works on everything it has been run on.
trouble is getting it to run on a 9370 and a PC/XT without major changes. ]
static int d_malcnt;
char *x_malloc (size)
int size;
{
char *cp;
char **tp;
if (! (cp = malloc (size + sizeof (char *))))
abort ();
d_malcnt++;
tp = (char **) cp;
*tp = &cp[sizeof (char *)];
return (*tp);
}
x_free (cp)
char *cp;
{
char **tp;
if (cp == (char *) 0)
abort ();
tp = (char **) &cp[- sizeof (char *)];
if (*tp != cp)
abort ();
*tp = (char *) 0;
free (tp);
if (! d_malcnt--)
abort ();
}
using this particular code (with the comments still present no less ;->
has helped me locate a countless number of bugs in the code. adding code
to check for the upper edge would help some too.
- john.
--
John F. Haugh II | "You see, I want a lot. Perhaps I want every
River Parishes Programming | -thing. The darkness that comes with every
UUCP: ihnp4!killer!rpp386!jfh | infinite fall and the shivering blaze of
DOMAIN: jfh at rpp386 | every step up ..." -- Rainer Maria Rilke
More information about the Comp.unix.wizards
mailing list