lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Re: [lwip] Proposal for magic numbers in LwIP


From: Shaun Jackman
Subject: [lwip-users] Re: [lwip] Proposal for magic numbers in LwIP
Date: Wed, 08 Jan 2003 22:34:07 -0000

Working with heap debugging on is a good idea. However, try not to 
reinvent the wheel. There are many libraries that do exactly this.
        ccmalloc
        debauch
        dmalloc
        fda
        electric-fence
Using these libraries does not genereally require altering the source 
code, so they're in effect free! They should work on the synthetic 
(Linux/BSD) targets without any trouble. With a bit of tweaking they 
could probably work on embedded targets as well (if not straight out 
of the box).

Cheers,
Shaun

> A good idea! What about wrapping it up in a macro that could be
> null #defined when compiled without debugging? Like this:
>
> s = mem_malloc();
> DEBUG_SETMAGIC(s, S_MAGIC_NUMBER);
>
> DEBUG_SETMAGIC(s, 0);
> mem_free(s);
>
> ... and
>
> DEBUG_CHEKCMAGIC(s, S_MAGIC_NUMBER);
>
> > I propose that all structures which are dynamically allocated
> > begin with a magic number. Before the structure is free'd this
> > number should be set to zero. My own practice is:
> >
> >   s = nalloc();
> >   memset (s, 0, sizeof (*s));
> >   s->magic = THE_MAGIC_OF_S;
> >
> >      ....
> >
> >   s->magic = 0;
> >   free (s);

[This message was sent through the lwip discussion list.]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]