[PATCH v4 02/10] vbscript: Reference count the vbscode_t.

Gabriel Ivăncescu gabrielopcode at gmail.com
Mon Nov 25 08:09:34 CST 2019


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/vbscript/compile.c  |  4 +++-
 dlls/vbscript/vbscript.c | 11 +++++++++--
 dlls/vbscript/vbscript.h |  1 +
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c
index 9ddfacf..d8ae0fc 100644
--- a/dlls/vbscript/compile.c
+++ b/dlls/vbscript/compile.c
@@ -1832,7 +1832,8 @@ void release_vbscode(vbscode_t *code)
 {
     unsigned i;
 
-    list_remove(&code->entry);
+    if(--code->ref)
+        return;
 
     for(i=0; i < code->bstr_cnt; i++)
         SysFreeString(code->bstr_pool[i]);
@@ -1875,6 +1876,7 @@ static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source)
 
     ret->main_code.type = FUNC_GLOBAL;
     ret->main_code.code_ctx = ret;
+    ret->ref = 1;
 
     list_init(&ret->entry);
     return ret;
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c
index f789036..94daace 100644
--- a/dlls/vbscript/vbscript.c
+++ b/dlls/vbscript/vbscript.c
@@ -223,7 +223,10 @@ static void release_script(script_ctx_t *ctx)
             if(code->last_class) code->last_class->next = NULL;
         }
         else
+        {
+            list_remove(&code->entry);
             release_vbscode(code);
+        }
     }
 
     while(!list_empty(&ctx->named_items)) {
@@ -262,8 +265,12 @@ static void release_script(script_ctx_t *ctx)
 
 static void release_code_list(script_ctx_t *ctx)
 {
-    while(!list_empty(&ctx->code_list))
-        release_vbscode(LIST_ENTRY(list_head(&ctx->code_list), vbscode_t, entry));
+    while(!list_empty(&ctx->code_list)) {
+        vbscode_t *iter = LIST_ENTRY(list_head(&ctx->code_list), vbscode_t, entry);
+
+        list_remove(&iter->entry);
+        release_vbscode(iter);
+    }
 }
 
 static void decrease_state(VBScript *This, SCRIPTSTATE state)
diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h
index f4e7bc7..2f1b61b 100644
--- a/dlls/vbscript/vbscript.h
+++ b/dlls/vbscript/vbscript.h
@@ -336,6 +336,7 @@ struct _function_t {
 struct _vbscode_t {
     instr_t *instrs;
     WCHAR *source;
+    unsigned ref;
 
     BOOL option_explicit;
 
-- 
2.21.0




More information about the wine-devel mailing list