Shifting the rest of the variables by one towards indices of lesser value overwrites the variable being cleared and effectively leaks it.
Signed-off-by: David Kahurani k.kahurani@gmail.com
From: David Kahurani k.kahurani@gmail.com
Shifting the rest of the variables by one towards indices of lesser value overwrites the variable being cleared and effectively leaks it.
Signed-off-by: David Kahurani k.kahurani@gmail.com --- dlls/msvcrt/environ.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcrt/environ.c b/dlls/msvcrt/environ.c index aa857afa615..09d2842366f 100644 --- a/dlls/msvcrt/environ.c +++ b/dlls/msvcrt/environ.c @@ -161,8 +161,15 @@ static int env_set(char **env, wchar_t **wenv) *eq = '='; if (!eq[1]) { + int start = idx; + for(; MSVCRT__environ[idx]; idx++) - MSVCRT__environ[idx] = MSVCRT__environ[idx + 1]; + { + if (idx == start) + free(MSVCRT__environ[start]); + + MSVCRT__environ[idx] = MSVCRT__environ[idx + 1]; + } } else if (MSVCRT__environ[idx]) { @@ -187,8 +194,15 @@ static int env_set(char **env, wchar_t **wenv) *weq = '='; if (!weq[1]) { + int start = idx; + for(; MSVCRT__wenviron[idx]; idx++) - MSVCRT__wenviron[idx] = MSVCRT__wenviron[idx + 1]; + { + if (idx == start) + free(MSVCRT__wenviron[start]); + + MSVCRT__wenviron[idx] = MSVCRT__wenviron[idx + 1]; + } } else if (MSVCRT__wenviron[idx]) {
please move the free() calls before & outside the for loop