[PATCH 0/1] MR1785: msi: Fix memory leak on realloc failure in search_directory (cppcheck).
From: Alex Henrie <alexhenrie24(a)gmail.com> --- dlls/msi/appsearch.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/dlls/msi/appsearch.c b/dlls/msi/appsearch.c index 9693fc92833..95c3312b3df 100644 --- a/dlls/msi/appsearch.c +++ b/dlls/msi/appsearch.c @@ -875,7 +875,7 @@ static UINT search_directory( MSIPACKAGE *package, MSISIGNATURE *sig, const WCHA { UINT rc; DWORD attr; - LPWSTR val = NULL; + WCHAR *val = NULL, *new_val; TRACE("%p, %p, %s, %d, %p\n", package, sig, debugstr_w(path), depth, appValue); @@ -920,11 +920,18 @@ static UINT search_directory( MSIPACKAGE *package, MSISIGNATURE *sig, const WCHA if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) && val && val[lstrlenW(val) - 1] != '\\') { - val = realloc(val, (wcslen(val) + 2) * sizeof(WCHAR)); - if (!val) + new_val = realloc(val, (wcslen(val) + 2) * sizeof(WCHAR)); + if (!new_val) + { + free(val); + val = NULL; rc = ERROR_OUTOFMEMORY; + } else + { + val = new_val; PathAddBackslashW(val); + } } *appValue = val; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/1785
This merge request was approved by Hans Leidekker. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/1785
participants (3)
-
Alex Henrie -
Alex Henrie (@alexhenrie) -
Hans Leidekker (@hans)