From cc1cfe132816771f4c8c89982dcf921e5fa33c46 Mon Sep 17 00:00:00 2001 From: q66 Date: Fri, 18 Dec 2015 15:06:42 +0100 Subject: [PATCH] fix cubescript func refcount --- main.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.cc b/main.cc index 04202ff..3e2fc93 100644 --- a/main.cc +++ b/main.cc @@ -246,6 +246,11 @@ struct ObState: CsState { cscript::bcode_ref(func); } ~Rule() { cscript::bcode_unref(func); } + + void set_func(Uint32 *c) { + func = c; + cscript::bcode_ref(func); + } }; Vector rules; @@ -448,10 +453,7 @@ struct ObState: CsState { Rule &r = rules.push(); r.target = target; r.action = action; - if (body) { - r.func = body; - cscript::bcode_ref(body); - } + r.set_func(body); r.deps = cscript::util::list_explode(dep); } } @@ -465,9 +467,9 @@ struct ObState: CsState { if (!oldr) return; Rule &r = rules.push(); + r.set_func(oldr->func); r.target = tgt; r.action = oldr->action; - r.func = oldr->func; r.deps = inherit_deps ? oldr->deps : cscript::util::list_explode(dep); }