lemoncake

rbtree based memory allocator
git clone git://git.2f30.org/lemoncake.git
Log | Files | Refs | README | LICENSE

commit 7915e540408259f295841cc47a2c545dc492e590
parent 5ff39dbe4898de660a02cbc365de2ca74344a4fa
Author: sin <sin@2f30.org>
Date:   Mon Aug  5 09:37:40 +0100

Abort if we try to free an invalid pointer in strict mode

Diffstat:
lemoncake.c | 6++++++
1 file changed, 6 insertions(+), 0 deletions(-)
diff --git a/lemoncake.c b/lemoncake.c @@ -16,6 +16,7 @@ /* Memory alignment for the allocation functions */ enum { ALIGN = 4 * sizeof(size_t) }; +static void writelog(int fd, const char *fmt, ...); static void dumpstats(void); struct lemon_stats { @@ -45,6 +46,7 @@ struct lemon_stats { static bool init; static struct lemon_stats st; +static bool strict = false; struct node { void *buf; @@ -285,6 +287,10 @@ free(void *p) st.nr_free++; } else { st.nr_invalid_free++; + if (strict) { + writelog(STDERR_FILENO, "*** Freeing invalid pointer: %p, aborting ***\n", p); + _Exit(1); + } } unlock(&rblock); }