From 8cc45af919dc56011dbf4c8965b9c1e4784e56d7 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Fri, 30 Aug 2019 10:42:50 -0400 Subject: In .developing mode, define MEMDEBUG to use malloc/free for block allocation to facilitate finding memory leaks. --- node.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'node.c') diff --git a/node.c b/node.c index 9574c3e7..eacd17b3 100644 --- a/node.c +++ b/node.c @@ -1034,6 +1034,25 @@ struct block_header nextfree[BLOCK_MAX] = { #endif }; +#ifdef MEMDEBUG + +void * +r_getblock(int id) +{ + void *res; + emalloc(res, void *, nextfree[id].size, "getblock"); + nextfree[id].cnt++; + return res; +} + +void +r_freeblock(void *p, int id) +{ + nextfree[id].cnt--; + free(p); +} + +#else /* more_blocks --- get more blocks of memory and add to the free list; size of a block must be >= sizeof(struct block_item) @@ -1064,3 +1083,5 @@ more_blocks(int id) nextfree[id].freep = freep->freep; return freep; } + +#endif -- cgit v1.2.3