From: Jacek Caban Subject: [PATCH 7/9] vbscript: Move create_script_disp call to SetScriptSite. Message-Id: <895e5574-cd7a-a2a7-0717-7b1185298ebe@codeweavers.com> Date: Fri, 18 Oct 2019 16:20:34 +0200 Signed-off-by: Jacek Caban --- dlls/vbscript/global.c | 12 ------------ dlls/vbscript/vbscript.c | 14 +++++++++++++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 0f85f66bad..364ff0c02c 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -2860,14 +2860,6 @@ void detach_global_objects(script_ctx_t *ctx) IDispatch_Release(&ctx->global_obj->IDispatch_iface); ctx->global_obj = NULL; } - - if(ctx->script_obj) { - ScriptDisp *script_obj = ctx->script_obj; - - ctx->script_obj = NULL; - script_obj->ctx = NULL; - IDispatchEx_Release(&script_obj->IDispatchEx_iface); - } } HRESULT init_global(script_ctx_t *ctx) @@ -2878,9 +2870,5 @@ HRESULT init_global(script_ctx_t *ctx) if(FAILED(hres)) return hres; - hres = create_script_disp(ctx, &ctx->script_obj); - if(FAILED(hres)) - return hres; - return create_builtin_dispatch(ctx, err_props, ARRAY_SIZE(err_props), &ctx->err_obj); } diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index ad5dea5498..8b81b7a5e3 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -182,6 +182,14 @@ static void release_script(script_ctx_t *ctx) ctx->site = NULL; } + if(ctx->script_obj) { + ScriptDisp *script_obj = ctx->script_obj; + + ctx->script_obj = NULL; + script_obj->ctx = NULL; + IDispatchEx_Release(&script_obj->IDispatchEx_iface); + } + detach_global_objects(ctx); heap_pool_free(&ctx->heap); heap_pool_init(&ctx->heap); @@ -415,6 +423,10 @@ static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScript if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0)) return E_UNEXPECTED; + hres = create_script_disp(This->ctx, &This->ctx->script_obj); + if(FAILED(hres)) + return hres; + This->ctx->site = pass; IActiveScriptSite_AddRef(This->ctx->site); @@ -514,7 +526,7 @@ static HRESULT WINAPI VBScript_AddNamedItem(IActiveScript *iface, LPCOLESTR pstr TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags); - if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED) + if(This->thread_id != GetCurrentThreadId() || !This->ctx->site) return E_UNEXPECTED; if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {