From f65e2d40cc394b716d53ba80c846237c84a68cf0 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 7 Feb 2017 16:23:38 +0100 Subject: [PATCH] lib: print backtrace on MTYPE count underflow Signed-off-by: David Lamparter --- lib/memory.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/memory.c b/lib/memory.c index f17915486c..5fc0088105 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -19,6 +19,7 @@ #include #include "memory.h" +#include "log.h" static struct memgroup *mg_first = NULL; struct memgroup **mg_insert = &mg_first; @@ -40,6 +41,11 @@ mt_count_alloc (struct memtype *mt, size_t size) static inline void mt_count_free (struct memtype *mt) { + if (mt->n_alloc == 0) + { + zlog_err ("memory allocation count underflow for \"%s\"", mt->name); + zlog_backtrace (LOG_ERR); + } mt->n_alloc--; }