home *** CD-ROM | disk | FTP | other *** search
- /*
- #### # # # #
- # # # # # The FreeWare C library for
- # # ## ### # # # # ### RISC OS machines
- # # # # # # # # # # # ___________________________________
- # # #### ### ## # # # #
- # # # # # # # # # # Please refer to the accompanying
- #### ### #### # # ##### # ### documentation for conditions of use
- ________________________________________________________________________
-
- File: Mem.CheckHeap.c
- Author: Copyright © 1994 Jason Howat
- Version: 1.00 (11 May 1994)
- Purpose: Dynamic memory manager - checks validity of heap
- */
-
- #include "MemDefs.h"
- #include "Error.h"
-
- extern BOOL Mem_CheckHeap(void)
- /* Returns TRUE if the heap data structure is valid (i.e. the links are all
- * intact and anchors are consistent)
- */
- {
- mem_header *chunk = (mem_header *) mem__heap,
- *next,
- *end_of_heap = (mem_header *) (mem__heap + mem__heapsize);
-
- while(TRUE)
- {
- if(!ISFREE(chunk) &&
- ((int) *(chunk->handle) != ((int) chunk + sizeof(mem_header))))
- {
- Error_Report(0,"Mem heap corrupt: Inconsistent chunk handle and anchor");
- return(FALSE);
- }
-
- if(chunk->realsize < chunk->datasize + sizeof(mem_header))
- {
- Error_Report(0, "Mem heap corrupt: Data larger than chunk");
- return(FALSE);
- }
-
- next = (mem_header *) ((int)chunk + chunk->realsize);
- if(next >= end_of_heap)
- break;
-
- if(chunk->realsize != next->prevrealsize)
- {
- Error_Report(0, "Mem heap corrupt: Chunk link(s) corrupt");
- return(FALSE);
- }
-
- chunk = next;
- }
-
- if(next != end_of_heap)
- {
- Error_Report(0, "Mem heap corrupt: Last chunk too big");
- return(FALSE);
- }
-
- return(TRUE);
- }
-