From 5265ce7837a185977f71bcb39a41b57492e24964 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Feb 2001 19:22:02 +0000 Subject: Added total memory allocated counter to talloc, so we can tell if a talloc pool is getting bloated. Also added a talloc_zero function to return zeroed memory. Added debug in rpc_server/srv_pipe_hnd.c so we know when a talloc pool is being freed. Syncup with srv_pipe_hnd.c from 2.2 so we are freeing memory at the same time. Jeremy. (This used to be commit d3a56c6042acf037bbd53de88d7636a5803ead20) --- source3/lib/talloc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/talloc.c') diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c index a04bd2561b..854a230a0e 100644 --- a/source3/lib/talloc.c +++ b/source3/lib/talloc.c @@ -47,6 +47,7 @@ TALLOC_CTX *talloc_init(void) if (!t) return NULL; t->list = NULL; + t->total_alloc_size = 0; return t; } @@ -82,6 +83,7 @@ void *talloc(TALLOC_CTX *t, size_t size) c->alloc_size = 0; c->total_size = asize; t->list = c; + t->total_alloc_size += asize; } p = ((char *)t->list->ptr) + t->list->alloc_size; @@ -107,6 +109,7 @@ void talloc_destroy_pool(TALLOC_CTX *t) } t->list = NULL; + t->total_alloc_size = 0; } /* destroy a whole pool including the context */ @@ -117,3 +120,22 @@ void talloc_destroy(TALLOC_CTX *t) talloc_destroy_pool(t); free(t); } + +/* return the current total size of the pool. */ +size_t talloc_pool_size(TALLOC_CTX *t) +{ + if (!t->list) + return 0; + return t->total_alloc_size; +} + +/* talloc and zero memory. */ +void *talloc_zero(TALLOC_CTX *t, size_t size) +{ + void *p = talloc(t, size); + + if (p) + memset(p, '\0', size); + + return p; +} -- cgit