Module: wine Branch: master Commit: 06395e5cd95fb5cbbc6724d9eddc0ca7bdc46842 URL: https://gitlab.winehq.org/wine/wine/-/commit/06395e5cd95fb5cbbc6724d9eddc0ca...
Author: Alex Henrie alexhenrie24@gmail.com Date: Mon Nov 28 22:30:40 2022 -0700
vbscript: Fix memory leak on realloc failure in Global_Split (cppcheck).
---
dlls/vbscript/global.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 98c705f4712..9eac80218fd 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -2574,7 +2574,7 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, { BSTR str, string, delimiter = NULL; int count, max, mode, len, start, end, ret, delimiterlen = 1; - int i,*indices = NULL, indices_max = 8; + int i, *indices = NULL, *new_indices, indices_max = 8; SAFEARRAYBOUND bounds; SAFEARRAY *sa = NULL; VARIANT *data, var; @@ -2656,12 +2656,13 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, }
if (count == indices_max) { - indices_max *= 2; - indices = realloc( indices, indices_max * sizeof(int)); - if(!indices) { + new_indices = realloc(indices, indices_max * 2 * sizeof(int)); + if(!new_indices) { hres = E_OUTOFMEMORY; goto error; } + indices = new_indices; + indices_max *= 2; } indices[count++] = end;