[PATCH v2 7/8] vbscript: Destroy the entire script context when the script engine is closed.

Gabriel Ivăncescu gabrielopcode at gmail.com
Wed Oct 30 07:57:25 CDT 2019


When the engine is closed, even the persistent code is removed.

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

Removing the context altogether is necessary for the future when it will
be ref counted (patch that will come after these).

 dlls/vbscript/vbscript.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c
index 53afd0b..e5d745b 100644
--- a/dlls/vbscript/vbscript.c
+++ b/dlls/vbscript/vbscript.c
@@ -255,7 +255,6 @@ static void destroy_script(script_ctx_t *ctx)
     while(!list_empty(&ctx->code_list))
         release_vbscode(LIST_ENTRY(list_head(&ctx->code_list), vbscode_t, entry));
 
-    release_script(ctx);
     heap_free(ctx);
 }
 
@@ -279,6 +278,11 @@ static void decrease_state(VBScript *This, SCRIPTSTATE state)
         change_state(This, state);
         release_script(This->ctx);
         This->thread_id = 0;
+        if(state == SCRIPTSTATE_CLOSED)
+        {
+            destroy_script(This->ctx);
+            This->ctx = NULL;
+        }
         break;
     case SCRIPTSTATE_CLOSED:
         break;
@@ -454,7 +458,6 @@ static ULONG WINAPI VBScript_Release(IActiveScript *iface)
 
     if(!ref) {
         decrease_state(This, SCRIPTSTATE_CLOSED);
-        destroy_script(This->ctx);
         heap_free(This);
     }
 
@@ -472,6 +475,9 @@ static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScript
     if(!pass)
         return E_POINTER;
 
+    if(FAILED(hres = init_ctx(This)))
+        return hres;
+
     if(This->ctx->site)
         return E_UNEXPECTED;
 
@@ -798,9 +804,13 @@ static ULONG WINAPI VBScriptParse_Release(IActiveScriptParse *iface)
 static HRESULT WINAPI VBScriptParse_InitNew(IActiveScriptParse *iface)
 {
     VBScript *This = impl_from_IActiveScriptParse(iface);
+    HRESULT hr;
 
     TRACE("(%p)\n", This);
 
+    if(FAILED(hr = init_ctx(This)))
+        return hr;
+
     if(This->is_initialized)
         return E_UNEXPECTED;
     This->is_initialized = TRUE;
@@ -966,12 +976,16 @@ static HRESULT WINAPI VBScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *if
         DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
 {
     VBScript *This = impl_from_IObjectSafety(iface);
+    HRESULT hr;
 
     TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
 
     if(!pdwSupportedOptions || !pdwEnabledOptions)
         return E_POINTER;
 
+    if(FAILED(hr = init_ctx(This)))
+        return hr;
+
     *pdwSupportedOptions = SUPPORTED_OPTIONS;
     *pdwEnabledOptions = This->ctx->safeopt;
     return S_OK;
@@ -981,12 +995,16 @@ static HRESULT WINAPI VBScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *if
         DWORD dwOptionSetMask, DWORD dwEnabledOptions)
 {
     VBScript *This = impl_from_IObjectSafety(iface);
+    HRESULT hr;
 
     TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
 
     if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
         return E_FAIL;
 
+    if(FAILED(hr = init_ctx(This)))
+        return hr;
+
     This->ctx->safeopt = (dwEnabledOptions & dwOptionSetMask) | (This->ctx->safeopt & ~dwOptionSetMask) | INTERFACE_USES_DISPEX;
     return S_OK;
 }
-- 
2.21.0




More information about the wine-devel mailing list