diff --git a/mpc.c b/mpc.c index 2869ee4..482230e 100644 --- a/mpc.c +++ b/mpc.c @@ -2512,6 +2512,7 @@ void mpc_ast_delete(mpc_ast_t *a) { mpc_ast_delete(a->children[i]); } + if (a->free) a->free(a->data); free(a->children); free(a->tag); free(a->contents); @@ -2520,6 +2521,7 @@ void mpc_ast_delete(mpc_ast_t *a) { } static void mpc_ast_delete_no_children(mpc_ast_t *a) { + if (a->free) a->free(a->data); free(a->children); free(a->tag); free(a->contents); @@ -2540,6 +2542,8 @@ mpc_ast_t *mpc_ast_new(const char *tag, const char *contents) { a->children_num = 0; a->children = NULL; + a->data = NULL; + a->free = NULL; return a; } diff --git a/mpc.h b/mpc.h index e75685c..9ef29a1 100644 --- a/mpc.h +++ b/mpc.h @@ -258,6 +258,8 @@ mpc_parser_t *mpc_re(const char *re); typedef struct mpc_ast_t { char *tag; char *contents; + void *data; + void (*free)(void*); mpc_state_t state; int children_num; struct mpc_ast_t** children;