From 28d434a20117eff271553b72057e330bfa8fb0fa Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 6 Nov 2022 02:11:12 +0200 Subject: [PATCH] catch double-frees in debug mode --- src/h.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/h.h b/src/h.h index eb3fced8..1fa5ebe6 100644 --- a/src/h.h +++ b/src/h.h @@ -578,12 +578,15 @@ static inline B inc(B x) { } static inline void decG(B x) { #if DEBUG - assert(isVal(x)); + assert(isVal(x) && v(x)->refc>0); #endif Value* vx = v(x); if(!--vx->refc) value_free(vx); } FORCE_INLINE void ptr_decT(Arr* x) { // assumes argument is an array and consists of non-heap-allocated elements + #if DEBUG + assert(x->refc>0); + #endif if (x->refc==1) TIv(x,freeT)((Value*) x); else x->refc--; }