[PATCH 5/7] vbscript: Use a helper function to init the script context.

Gabriel Ivăncescu gabrielopcode at gmail.com
Tue Oct 29 10:19:38 CDT 2019


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

Needed for next patch.

 dlls/vbscript/vbscript.c | 42 ++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c
index 79a27d1..d751c57 100644
--- a/dlls/vbscript/vbscript.c
+++ b/dlls/vbscript/vbscript.c
@@ -73,6 +73,32 @@ static void change_state(VBScript *This, SCRIPTSTATE state)
         IActiveScriptSite_OnStateChange(This->ctx->site, state);
 }
 
+static HRESULT init_ctx(VBScript *vbscript)
+{
+    script_ctx_t *ctx;
+    HRESULT hr;
+
+    if (vbscript->ctx) return S_OK;
+
+    ctx = heap_alloc_zero(sizeof(*ctx));
+    if (!ctx) return E_OUTOFMEMORY;
+
+    ctx->safeopt = INTERFACE_USES_DISPEX;
+    list_init(&ctx->objects);
+    list_init(&ctx->code_list);
+    list_init(&ctx->named_items);
+
+    hr = init_global(ctx);
+    if (FAILED(hr))
+    {
+        heap_free(ctx);
+        return hr;
+    }
+
+    vbscript->ctx = ctx;
+    return S_OK;
+}
+
 static inline BOOL is_started(VBScript *This)
 {
     return This->state == SCRIPTSTATE_STARTED
@@ -961,7 +987,6 @@ static const IObjectSafetyVtbl VBScriptSafetyVtbl = {
 
 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
 {
-    script_ctx_t *ctx;
     VBScript *ret;
     HRESULT hres;
 
@@ -980,20 +1005,9 @@ HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pU
     ret->ref = 1;
     ret->state = SCRIPTSTATE_UNINITIALIZED;
 
-    ctx = ret->ctx = heap_alloc_zero(sizeof(*ctx));
-    if(!ctx) {
+    if(FAILED(hres = init_ctx(ret)))
+    {
         heap_free(ret);
-        return E_OUTOFMEMORY;
-    }
-
-    ctx->safeopt = INTERFACE_USES_DISPEX;
-    list_init(&ctx->objects);
-    list_init(&ctx->code_list);
-    list_init(&ctx->named_items);
-
-    hres = init_global(ctx);
-    if(FAILED(hres)) {
-        IActiveScript_Release(&ret->IActiveScript_iface);
         return hres;
     }
 
-- 
2.21.0




More information about the wine-devel mailing list