[PATCH v3 6/9] vbscript: Use a helper function to init the script context.
Gabriel Ivăncescu
gabrielopcode at gmail.com
Fri Nov 1 10:05:07 CDT 2019
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
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 224e030..16759ea 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
@@ -972,7 +998,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;
@@ -991,20 +1016,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