From 40f31a90505a7da26a8b08aacfbf551cf46f620e Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Thu, 18 May 2023 21:16:20 +0200 Subject: [PATCH] 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 --- repos/libports/src/lib/libc/malloc.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/repos/libports/src/lib/libc/malloc.cc b/repos/libports/src/lib/libc/malloc.cc index 0ec76918ef..f9af5efb6b 100644 --- a/repos/libports/src/lib/libc/malloc.cc +++ b/repos/libports/src/lib/libc/malloc.cc @@ -221,6 +221,10 @@ class Libc::Malloc 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) { _backing_store.free(alloc_addr, real_size); } else {