Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/vbscript/vbscript.c | 46 ++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-)
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index 52bc4ff..858cacb 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -262,6 +262,7 @@ void release_named_item(named_item_t *item)
static void release_script(script_ctx_t *ctx) { + named_item_t *item, *item_next; vbscode_t *code, *code_next;
collect_objects(ctx); @@ -282,14 +283,19 @@ static void release_script(script_ctx_t *ctx) } }
- while(!list_empty(&ctx->named_items)) { - named_item_t *iter = LIST_ENTRY(list_head(&ctx->named_items), named_item_t, entry); - - list_remove(&iter->entry); - if(iter->disp) - IDispatch_Release(iter->disp); - release_named_item_script_obj(iter); - release_named_item(iter); + LIST_FOR_EACH_ENTRY_SAFE(item, item_next, &ctx->named_items, named_item_t, entry) + { + if(item->disp) + { + IDispatch_Release(item->disp); + item->disp = NULL; + } + release_named_item_script_obj(item); + if(!(item->flags & SCRIPTITEM_ISPERSISTENT)) + { + list_remove(&item->entry); + release_named_item(item); + } }
if(ctx->secmgr) { @@ -321,6 +327,15 @@ static void release_code_list(script_ctx_t *ctx) } }
+static void release_named_item_list(script_ctx_t *ctx) +{ + while(!list_empty(&ctx->named_items)) { + named_item_t *iter = LIST_ENTRY(list_head(&ctx->named_items), named_item_t, entry); + list_remove(&iter->entry); + release_named_item(iter); + } +} + static void decrease_state(VBScript *This, SCRIPTSTATE state) { switch(This->state) { @@ -340,8 +355,10 @@ static void decrease_state(VBScript *This, SCRIPTSTATE state) break; release_script(This->ctx); This->thread_id = 0; - if(state == SCRIPTSTATE_CLOSED) + if(state == SCRIPTSTATE_CLOSED) { release_code_list(This->ctx); + release_named_item_list(This->ctx); + } break; case SCRIPTSTATE_CLOSED: break; @@ -539,6 +556,7 @@ static ULONG WINAPI VBScript_Release(IActiveScript *iface) static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass) { VBScript *This = impl_from_IActiveScript(iface); + named_item_t *item; LCID lcid; HRESULT hres;
@@ -553,6 +571,16 @@ static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScript if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0)) return E_UNEXPECTED;
+ /* Retrieve new dispatches for persistent named items */ + LIST_FOR_EACH_ENTRY(item, &This->ctx->named_items, named_item_t, entry) + { + if(!item->disp) + { + hres = retrieve_named_item_disp(pass, item); + if(FAILED(hres)) return hres; + } + } + hres = create_script_disp(This->ctx, &This->ctx->script_obj); if(FAILED(hres)) return hres;