From 56d8008672676492d844d42bb6f46771b2ebb425 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Tue, 31 Oct 2006 21:08:12 +0000 Subject: [PATCH] Fix QB4 MCB problem (from FD1.0 kernel). git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1304 6ac86273-5f31-0410-b378-82cca8765d1b --- kernel/memmgr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kernel/memmgr.c b/kernel/memmgr.c index 987143f..1ec7c66 100644 --- a/kernel/memmgr.c +++ b/kernel/memmgr.c @@ -38,7 +38,9 @@ static BYTE *memmgrRcsId = #define nxtMCB(mcb) nxtMCBsize((mcb), (mcb)->m_size) #define mcbFree(mcb) ((mcb)->m_psp == FREE_PSP) -#define mcbValid(mcb) \ +#define mcbValid(mcb) ( ((mcb)->m_size != 0xffff) && \ + ((mcb)->m_type == MCB_NORMAL || (mcb)->m_type == MCB_LAST) ) +#define mcbFreeable(mcb) \ ((mcb)->m_type == MCB_NORMAL || (mcb)->m_type == MCB_LAST) #define para2far(seg) (mcb FAR *)MK_FP((seg) , 0) @@ -66,7 +68,11 @@ STATIC COUNT joinMCBs(seg para) /* join both MCBs */ p->m_type = q->m_type; /* possibly the next MCB is the last one */ p->m_size += q->m_size + 1; /* one for q's MCB itself */ - q->m_type = 'K'; /* Invalidate the magic number */ +#if 0 /* this spoils QB4's habit to double-free: */ + q->m_type = 'K'; /* Invalidate the magic number (whole MCB) */ +#else + q->m_size = 0xffff; /* mark the now unlinked MCB as "fake" */ +#endif } return SUCCESS; @@ -289,7 +295,7 @@ COUNT DosMemFree(UWORD para) p = para2far(para); /* check for corruption */ - if (!mcbValid(p)) + if (!mcbFreeable(p)) /* does not have to be valid, freeable is enough */ return DE_INVLDMCB; /* Mark the mcb as free so that we can later */