if MKSH_AFREE_DEBUG is defined, guard against wrong frees

This commit is contained in:
tg 2008-07-13 16:43:55 +00:00
parent 04bc7ba51a
commit a9f219dd60
2 changed files with 16 additions and 3 deletions

View File

@ -1,9 +1,9 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.339 2008/07/11 19:51:22 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.340 2008/07/13 16:43:54 tg Exp $'
#-
# Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS
# CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NOPWNAM MKSH_NOVI
# MKSH_CLS_STRING
# MKSH_CLS_STRING MKSH_AFREE_DEBUG
LC_ALL=C
export LC_ALL

15
alloc.c
View File

@ -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