diff options
Diffstat (limited to 'src/chheap.c')
-rw-r--r-- | src/chheap.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/chheap.c b/src/chheap.c index f2bcc2b9e..adfe2842f 100644 --- a/src/chheap.c +++ b/src/chheap.c @@ -153,16 +153,20 @@ void *chHeapAlloc(size_t size) { void chHeapFree(void *p) {
struct header *qp, *hp;
- hp = (struct header *)p - 1;
-
- chDbgAssert(hp->h_magic == MAGIC, "chheap.c, chHeapFree() #1");
+ chDbgCheck(p != NULL, "chHeapFree");
+ hp = (struct header *)p - 1;
+ chDbgAssert(hp->h_magic == MAGIC,
+ "chHeapFree(), #1",
+ "it is not magic");
qp = &heap.free;
H_LOCK();
while (TRUE) {
- chDbgAssert((hp < qp) || (hp >= LIMIT(qp)), "chheap.c, chHeapFree() #2");
+ chDbgAssert((hp < qp) || (hp >= LIMIT(qp)),
+ "chHeapFree(), #2",
+ "within free block");
if (((qp == &heap.free) || (hp > qp)) &&
((qp->h_next == NULL) || (hp < qp->h_next))) {
@@ -244,19 +248,17 @@ void *chHeapAlloc(size_t size) { void *p;
H_LOCK();
-
p = malloc(size);
-
H_UNLOCK();
return p;
}
void chHeapFree(void *p) {
- H_LOCK();
+ chDbgCheck(p != NULL, "chHeapFree");
+ H_LOCK();
free(p);
-
H_UNLOCK();
}
|