libc: add message for corrupted allocation on 'free'

In case the meta data (or more) got zeroed upon 'free', print error
message. The offset in the meta data can never be zero. This does not
help on other memory corruptions, but at least gives a hint in the too
much zeroed out case.

issue #4675
This commit is contained in:
Sebastian Sumpf 2023-05-18 21:16:20 +02:00 committed by Christian Helmuth
parent 4c98be54eb
commit 40f31a9050

View File

@ -221,6 +221,10 @@ class Libc::Malloc
void *alloc_addr = (void *)((addr_t)ptr - md->offset); void *alloc_addr = (void *)((addr_t)ptr - md->offset);
if (md->offset == 0)
error("libc free: meta-data offset is 0 for address: ", ptr,
" - corrupted allocation");
if (msb > SLAB_STOP) { if (msb > SLAB_STOP) {
_backing_store.free(alloc_addr, real_size); _backing_store.free(alloc_addr, real_size);
} else { } else {