if MKSH_AFREE_DEBUG is defined, guard against wrong frees
This commit is contained in:
15
alloc.c
15
alloc.c
@ -29,7 +29,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.6 2007/06/05 18:59:54 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.7 2008/07/13 16:43:55 tg Exp $");
|
||||
|
||||
struct link {
|
||||
struct link *prev;
|
||||
@ -102,12 +102,25 @@ void
|
||||
afree(void *ptr, Area *ap)
|
||||
{
|
||||
struct link *l;
|
||||
#ifdef MKSH_AFREE_DEBUG
|
||||
struct link *lp;
|
||||
#endif
|
||||
|
||||
if (!ptr)
|
||||
return;
|
||||
|
||||
l = P2L(ptr);
|
||||
|
||||
#ifdef MKSH_AFREE_DEBUG
|
||||
for (lp = ap->freelist; lp != NULL; lp = lp->next)
|
||||
if (l == lp)
|
||||
break;
|
||||
if (lp == NULL) {
|
||||
internal_warningf("afree: pointer %p not allocated", ptr);
|
||||
exit(255);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (l->prev)
|
||||
l->prev->next = l->next;
|
||||
else
|
||||
|
Reference in New Issue
Block a user