[PATCH 3/3] jscript: Release all globals when the script ctx is destroyed or re-initialized.

Gabriel Ivăncescu gabrielopcode at gmail.com
Mon May 30 12:24:24 CDT 2022


Most of these globals were leaking before as they were never freed at
all. Also, they have to be freed during script ctx destruction because an
unintialized script might still make use of them (e.g. retrieving a builtin
function via PROPERTYGET requires ctx->function_constr to be available),
so freeing them during state transition would crash.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---

The previous patch already has tests for that builtin PROPERTYGET thing.

 dlls/jscript/global.c  |  1 +
 dlls/jscript/jscript.c | 16 +---------------
 dlls/jscript/jscript.h | 12 ++++++++++++
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index c0ed954..1852cd3 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -1085,6 +1085,7 @@ HRESULT init_global(script_ctx_t *ctx)
 
     if(ctx->global)
         return S_OK;
+    globals_release(ctx);
 
     hres = create_dispex(ctx, &JSGlobal_info, NULL, &ctx->global);
     if(FAILED(hres))
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index d6028e6..01249c4 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -76,6 +76,7 @@ void script_release(script_ctx_t *ctx)
     if(--ctx->ref)
         return;
 
+    globals_release(ctx);
     jsval_release(ctx->acc);
     if(ctx->cc)
         release_cc(ctx->cc);
@@ -483,21 +484,6 @@ static void decrease_state(JScript *This, SCRIPTSTATE state)
                 This->ctx->site = NULL;
             }
 
-            if(This->ctx->map_prototype) {
-                jsdisp_release(This->ctx->map_prototype);
-                This->ctx->map_prototype = NULL;
-            }
-
-            if(This->ctx->set_prototype) {
-                jsdisp_release(This->ctx->set_prototype);
-                This->ctx->set_prototype = NULL;
-            }
-
-            if(This->ctx->object_prototype) {
-                jsdisp_release(This->ctx->object_prototype);
-                This->ctx->object_prototype = NULL;
-            }
-
             if(This->ctx->global) {
                 jsdisp_release(This->ctx->global);
                 This->ctx->global = NULL;
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 000bcc2..f635c09 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -411,6 +411,18 @@ struct _script_ctx_t {
     jsdisp_t *set_prototype;
 };
 
+static inline void globals_release(script_ctx_t *ctx)
+{
+    jsdisp_t **iter = &ctx->function_constr, **end = &ctx->set_prototype + 1;
+    while(iter != end) {
+        if(*iter) {
+            jsdisp_release(*iter);
+            *iter = NULL;
+        }
+        iter++;
+    }
+}
+
 void script_release(script_ctx_t*) DECLSPEC_HIDDEN;
 
 static inline void script_addref(script_ctx_t *ctx)
-- 
2.34.1




More information about the wine-devel mailing list