From 3fc90383a90f7a636eabd5f03e08a41a60e81f26 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 12 Jun 2018 23:47:40 -0700 Subject: [PATCH] Increment refcount for tree when added to function. --- src/custom.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/custom.c b/src/custom.c index 39440ec..ecb65ac 100644 --- a/src/custom.c +++ b/src/custom.c @@ -9,6 +9,7 @@ void libab_behavior_init_internal(libab_behavior* behavior, void libab_behavior_init_tree(libab_behavior* behavior, libab_tree* tree) { behavior->variant = BIMPL_TREE; behavior->data_u.tree = tree; + tree->int_value++; } void libab_behavior_copy(libab_behavior* behavior, libab_behavior* into) { @@ -42,21 +43,24 @@ libab_result libab_function_init_internal(libab_function* function, libab_function_ptr fun, libab_ref* scope) { libab_result result = _function_init(function, scope); - libab_behavior_init_internal(&function->behavior, fun); + if(result == LIBAB_SUCCESS) + libab_behavior_init_internal(&function->behavior, fun); return result; } libab_result libab_function_init_tree(libab_function* function, libab_tree* tree, libab_ref* scope) { libab_result result = _function_init(function, scope); - libab_behavior_init_tree(&function->behavior, tree); + if(result == LIBAB_SUCCESS) + libab_behavior_init_tree(&function->behavior, tree); return result; } libab_result libab_function_init_behavior(libab_function* function, libab_behavior* behavior, libab_ref* scope) { libab_result result = _function_init(function, scope); - libab_behavior_copy(behavior, &function->behavior); + if(result == LIBAB_SUCCESS) + libab_behavior_copy(behavior, &function->behavior); return result; } void libab_function_free(libab_function* fun) {