fix off-by-1 screen title fill
[AROS.git] / rom / exec / deallocate.c
blobfd9ae9c0fcd577bfd7d9190e552a0b3842f95fc8
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Free memory allocated by Allocate().
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <exec/execbase.h>
11 #include <exec/alerts.h>
12 #include <aros/libcall.h>
13 #include <exec/memory.h>
14 #include <exec/memheaderext.h>
15 #include <proto/exec.h>
17 #include "exec_util.h"
18 #include "memory.h"
20 /*****************************************************************************
22 NAME */
24 AROS_LH3(void, Deallocate,
26 /* SYNOPSIS */
27 AROS_LHA(struct MemHeader *, freeList, A0),
28 AROS_LHA(APTR, memoryBlock, A1),
29 AROS_LHA(IPTR, byteSize, D0),
31 /* LOCATION */
32 struct ExecBase *, SysBase, 32, Exec)
34 /* FUNCTION
35 Free block of memory associated with a given MemHandler structure.
37 INPUTS
38 freeList - Pointer to the MemHeader structure
39 memoryBlock - Pointer to the memory to be freed
40 byteSize - Size of the block
42 RESULT
44 NOTES
45 The start and end borders of the block are aligned to
46 a multiple of sizeof(struct MemChunk) and to include the block.
48 EXAMPLE
50 BUGS
52 SEE ALSO
53 Allocate()
55 INTERNALS
57 ******************************************************************************/
59 AROS_LIBFUNC_INIT
61 if ((freeList->mh_Node.ln_Type == NT_MEMORY) &&
62 (freeList->mh_Attributes & MEMF_MANAGED) &&
63 (((struct MemHeaderExt *)freeList)->mhe_Magic == MEMHEADER_EXT_MAGIC)
66 struct MemHeaderExt *mhe = (struct MemHeaderExt *)freeList;
68 if (mhe->mhe_Free)
69 mhe->mhe_Free(mhe, memoryBlock, byteSize);
71 else
73 struct TraceLocation tp = CURRENT_LOCATION("Deallocate");
75 /* If there is no memory free nothing */
76 if(!byteSize || !memoryBlock)
77 return;
79 #if !defined(NO_CONSISTENCY_CHECKS)
80 /* Test if our block really fits into this MemHeader. */
81 if ((memoryBlock < freeList->mh_Lower) || (memoryBlock + byteSize > freeList->mh_Upper + 1))
83 /* Something is completely wrong. */
84 bug("[MM] Memory allocator error\n");
85 bug("[MM] Attempt to free %u bytes at 0x%p from MemHeader 0x%p\n", byteSize, memoryBlock, freeList);
86 bug("[MM] Block does not fit into MemHeader (0x%p - 0x%p)\n", freeList->mh_Lower, freeList->mh_Upper);
88 Alert(AN_BadFreeAddr);
89 return;
91 #endif
93 stdDealloc(freeList, NULL /* by design */, memoryBlock, byteSize, &tp, SysBase);
97 AROS_LIBFUNC_EXIT
98 } /* Deallocate */