| 254 | } |
| 255 | |
| 256 | void free(void *ptr) |
| 257 | { |
| 258 | hdrtype_t hdr; |
| 259 | struct memory_type *type = heap; |
| 260 | |
| 261 | /* No action occurs on NULL. */ |
| 262 | if (ptr == NULL) |
| 263 | return; |
| 264 | |
| 265 | /* Sanity check. */ |
| 266 | if (ptr < type->start || ptr >= type->end) { |
| 267 | type = dma; |
| 268 | if (ptr < type->start || ptr >= type->end) |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | if (free_aligned(ptr, type)) return; |
| 273 | |
| 274 | ptr -= HDRSIZE; |
| 275 | hdr = *((hdrtype_t *) ptr); |
| 276 | |
| 277 | /* Not our header (we're probably poisoned). */ |
| 278 | if (!HAS_MAGIC(hdr)) |
| 279 | return; |
| 280 | |
| 281 | /* Double free. */ |
| 282 | if (hdr & FLAG_FREE) |
| 283 | return; |
| 284 | |
| 285 | *((hdrtype_t *) ptr) = FREE_BLOCK(SIZE(hdr)); |
| 286 | _consolidate(type); |
| 287 | } |
| 288 | |
| 289 | void *malloc(size_t size) |
| 290 | { |