From 1660a2954797e056caba319c5d6c70b0d4be22fe Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 23 Jun 2010 18:11:51 -0700 Subject: exec_node: Add new talloc-based new() And fix all callers to use the tallbac-based new for exec_node construction. We make ready use of talloc_parent in order to get valid, (and appropriate) talloc owners for everything we construct without having to add new 'ctx' parameters up and down all the call trees. This closes the majority of the memory leaks in the glsl-orangebook-ch06-bump.frag test: total heap usage: 55,623 allocs, 42,672 frees (was 14,533 frees) Now 76.7% leak-free. Woo-hoo! --- list.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'list.h') diff --git a/list.h b/list.h index 0b91647be4..7732d66d7a 100644 --- a/list.h +++ b/list.h @@ -66,7 +66,13 @@ #ifndef __cplusplus #include +#include +#else +extern "C" { +#include +} #endif + #include struct exec_node { @@ -74,6 +80,25 @@ struct exec_node { struct exec_node *prev; #ifdef __cplusplus + /* Callers of this talloc-based new need not call delete. It's + * easier to just talloc_free 'ctx' (or any of its ancestors). */ + static void* operator new(size_t size, void *ctx) + { + void *node; + + node = talloc_size(ctx, size); + assert(node != NULL); + + return node; + } + + /* If the user *does* call delete, that's OK, we will just + * talloc_free in that case. */ + static void operator delete(void *node) + { + talloc_free(node); + } + exec_node() : next(NULL), prev(NULL) { /* empty */ -- cgit v1.2.3