diff options
author | Carl Worth <cworth@cworth.org> | 2010-06-23 17:12:11 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2010-06-23 18:15:28 -0700 |
commit | 8f52c9b5fcbc73ed12b23253caa44c28fd4452e2 (patch) | |
tree | 9095f97434e32130abced75cadf4c10e8389a6be /ast.h | |
parent | 015b3a5115df9a53b73d4b99fed86cf245c87aca (diff) |
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)
Diffstat (limited to 'ast.h')
-rw-r--r-- | ast.h | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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); |