[PATCH v5 0/1] MR2132: vbscript: Fix memory leak in interp_redim_preserve
While running in XCode's profiler, I noticed two memory leaks in `interp_redim_preserve`. After looking at `interp_redim`, the `bounds` structure is freed. I've updated `interp_redim_preserve` to free `bounds` when the array is NULL and not NULL. -- v5: vbscript: Fix memory leak in Split() https://gitlab.winehq.org/wine/wine/-/merge_requests/2132
From: Jason Millard <jsm174(a)gmail.com> --- dlls/vbscript/interp.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index b3be3bea6cf..4881efa9454 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -1375,24 +1375,31 @@ static HRESULT interp_redim_preserve(exec_ctx_t *ctx) if(array == NULL || array->cDims == 0) { /* can initially allocate the array */ array = SafeArrayCreate(VT_VARIANT, dim_cnt, bounds); - VariantClear(v); - V_VT(v) = VT_ARRAY|VT_VARIANT; - V_ARRAY(v) = array; - return S_OK; + if(!array) + hres = E_OUTOFMEMORY; + else { + VariantClear(v); + V_VT(v) = VT_ARRAY|VT_VARIANT; + V_ARRAY(v) = array; + } } else if(array->cDims != dim_cnt) { /* can't otherwise change the number of dimensions */ TRACE("Can't resize %s, cDims %d != %d\n", debugstr_w(identifier), array->cDims, dim_cnt); - return MAKE_VBSERROR(VBSE_OUT_OF_BOUNDS); + hres = MAKE_VBSERROR(VBSE_OUT_OF_BOUNDS); } else { /* can resize the last dimensions (if others match */ for(i = 0; i+1 < dim_cnt; ++i) { if(array->rgsabound[array->cDims - 1 - i].cElements != bounds[i].cElements) { TRACE("Can't resize %s, bound[%d] %ld != %ld\n", debugstr_w(identifier), i, array->rgsabound[i].cElements, bounds[i].cElements); - return MAKE_VBSERROR(VBSE_OUT_OF_BOUNDS); + hres = MAKE_VBSERROR(VBSE_OUT_OF_BOUNDS); + break; } } - return SafeArrayRedim(array, &bounds[dim_cnt-1]); + if(SUCCEEDED(hres)) + hres = SafeArrayRedim(array, &bounds[dim_cnt-1]); } + free(bounds); + return hres; } static HRESULT interp_step(exec_ctx_t *ctx) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2132
participants (2)
-
Jason Millard -
Jason Millard (@jsm174)