if MKSH_AFREE_DEBUG is defined, guard against wrong frees
This commit is contained in:
parent
04bc7ba51a
commit
a9f219dd60
4
Build.sh
4
Build.sh
|
@ -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
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
|
||||
|
|
Loading…
Reference in New Issue