[PATCH 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. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2132
From: Jason Millard <jsm174(a)gmail.com> --- dlls/vbscript/interp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index b3be3bea6cf..ee7cde763a6 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -1375,6 +1375,7 @@ 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); + free(bounds); VariantClear(v); V_VT(v) = VT_ARRAY|VT_VARIANT; V_ARRAY(v) = array; @@ -1391,7 +1392,9 @@ static HRESULT interp_redim_preserve(exec_ctx_t *ctx) return MAKE_VBSERROR(VBSE_OUT_OF_BOUNDS); } } - return SafeArrayRedim(array, &bounds[dim_cnt-1]); + hres = SafeArrayRedim(array, &bounds[dim_cnt-1]); + free(bounds); + return hres; } } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2132
There are also leaks in error cases. I think it would be a bit cleaner if those if() branches would only set hres (without returning) and just have free bounds in the end of the function: ``` free(bounds); return hres; ``` -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2132#note_23410
participants (3)
-
Jacek Caban (@jacek) -
Jason Millard -
Jason Millard (@jsm174)