[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] [lwip] Proposal for magic numbers in LwIP
From: |
Paul Sheer |
Subject: |
[lwip-users] [lwip] Proposal for magic numbers in LwIP |
Date: |
Wed, 08 Jan 2003 22:45:07 -0000 |
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);
now before every occurance of the use of s, should come the line:
magic (s, THE_MAGIC_OF_S);
if (s->some_member == x) { ...
where magic() is defined as
#define magic(e,m) \
do { \
if ((e)->magic != (m)) { \
__die (__FILE__, __FUNCTION__, __LINE__, \
"magic: (%s)->magic != %p(%s): magic failed for pointer %p", \
#e, (void *) (m), #m, (void *) (e)); \
} \
} while (0)
which gives you a lot of useful info.
(__die() is PaulOS specific and does print a traceback.)
this should really catch any problems.
i'll send a patch soon where I use magic
everywhere in pcb structs, pbufs etc.
additionally you can add a traceback array member to the
struct that gets filled before the struct is free'd.
if it is free'd again it is easy to see how it
was free'd the first time. - but thats another story.
best
-paul
Paul Sheer Consulting IT Services . . . Tel . . . +27 21 761 7224
Email . . . address@hidden . . . . . . Pager . . . 088 0057245
Linux development, cryptography, recruitment, support, training
http://www.icon.co.za/~psheer . . . . http://rute.sourceforge.net
L I N U X . . . . . . . . . . . . The Choice of a GNU Generation
[This message was sent through the lwip discussion list.]
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lwip-users] [lwip] Proposal for magic numbers in LwIP,
Paul Sheer <=