| 823 | } |
| 824 | |
| 825 | void AST_Free |
| 826 | ( |
| 827 | AST *ast |
| 828 | ) { |
| 829 | if(ast == NULL) return; |
| 830 | |
| 831 | int ref_count = AST_DecRefCount(ast); |
| 832 | |
| 833 | // check if the ast has additional copies |
| 834 | if(ref_count == 0) { |
| 835 | // free and nullify parameters parse result if needed |
| 836 | // after execution, as they are only save for the execution lifetime |
| 837 | if(ast->params_parse_result != NULL) { |
| 838 | parse_result_free(ast->params_parse_result); |
| 839 | } |
| 840 | |
| 841 | // no valid references, the struct can be disposed completely |
| 842 | if(ast->free_root) { |
| 843 | // this is a generated AST, free its root node |
| 844 | cypher_astnode_free((cypher_astnode_t *) ast->root); |
| 845 | } else { |
| 846 | // this is the master AST |
| 847 | // free the annotation contexts that have been constructed |
| 848 | AST_AnnotationCtxCollection_Free(ast->anot_ctx_collection); |
| 849 | parse_result_free(ast->parse_result); |
| 850 | } |
| 851 | |
| 852 | if(ast->referenced_entities) raxFree(ast->referenced_entities); |
| 853 | |
| 854 | rm_free(ast->ref_count); |
| 855 | } |
| 856 | |
| 857 | rm_free(ast); |
| 858 | } |
| 859 | |