From 8f52c9b5fcbc73ed12b23253caa44c28fd4452e2 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 23 Jun 2010 17:12:11 -0700 Subject: ast_node: Add new talloc-based new() And use the talloc-based new for all of the ast objects created by the parser. This closes a lot of memory leaks, and will allow us to use these ast objects as talloc parents in the future, (for things like exec_nodes, etc.). This closes 164 leaks in the glsl-orangebook-ch06-bump.frag test: total heap usage: 55,623 allocs, 14,553 frees (was 14,389 frees) --- ast.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ast.h') diff --git a/ast.h b/ast.h index 782e2c7ce7..de300e719c 100644 --- a/ast.h +++ b/ast.h @@ -36,6 +36,25 @@ struct YYLTYPE; class ast_node { public: + /* 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 *table) + { + talloc_free(table); + } + virtual void print(void) const; virtual ir_rvalue *hir(exec_list *instructions, struct _mesa_glsl_parse_state *state); -- cgit v1.2.3