[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gEDA-dev: PCB MyFree




> Umm, except I would pass x to xfree, and then set (x)=0.

Whatever.

> > Plus it gives us a hook for other things, like if we always pass
> > file/line to all malloc/free, we can actually allocate extra memory
> > and store the file/line in it, to help us track down memory problems.
> 
> Given the choice, I'd rather add this feature to dmalloc.
> Maybe dmalloc already has it?

Perhaps, but dmalloc isn't the only malloc debugger out there, and who
am I do try to predict what kind of weird debugging printfs I or
others might need in the future?  I've sometimes found myself adding
printfs to EVERY malloc/free, dumping the pointer, as well as other
printfs printing out pointers, then using grep or perl to figure out
the patterns and "what happened?"s.

> void *xcalloc_function(const char *file, int line, size_t nmemb, size_t size)
> {
> 	void *rv;
> #ifdef __DMALLOC_H__
> 	rv = dmalloc_malloc(file, line, (nmemb)*(size), DMALLOC_FUNC_CALLOC, 0, 0);
> #else
> 	rv = malloc((nmemb)*(size));

xcalloc should call calloc, not malloc.

> At least compiles without warnings.  This has to be duplicated
> four times (calloc, malloc, realloc, strdup).

Five.  xfree().

> It should work on my machine, but it seems a little too chummy with
> the dmalloc implementation.

I'm not going to complain about that, as long as it's encapsulated in
one spot.

> #ifdef __DMALLOC_H__
> #if DMALLOC_VERSION_MAJOR != 5 || DMALLOC_VERSION_MINOR != 4
> #warning this code untested against this dmalloc version
> #endif
> #endif

Or use those defines to add ot the DMALLOC_H conditional, so that for
older versions (what about dmalloc 6? ;) we just call malloc() and let
the dmalloc.h #define it however it wants.
_______________________________________________
geda-dev mailing list
geda-dev@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev