[PATCH 0/1] MR5827: shell32: Fix possible handle leak
If the malloc(3) had failed to allocate the memory, it returned nonzero value, but the 'file' handle was kept open. This closes the handle before return from the `init_xdg_dirs()` if the malloc(3) has failed. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/5827
From: Ruslan Garipov <ruslanngaripov(a)gmail.com> If the malloc(3) had failed to allocate the memory, it returned nonzero value, but the 'file' handle was kept open. This closes the handle before return from the init_xdg_dirs() if the malloc(3) has failed. Signed-off-by: Ruslan Garipov <ruslanngaripov(a)gmail.com> --- dlls/shell32/shellpath.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c index 7fbded5743b..068859b9571 100644 --- a/dlls/shell32/shellpath.c +++ b/dlls/shell32/shellpath.c @@ -2678,7 +2678,11 @@ static BOOL WINAPI init_xdg_dirs( INIT_ONCE *once, void *param, void **context ) if (file != INVALID_HANDLE_VALUE) { len = GetFileSize( file, NULL ); - if (!(xdg_config = malloc( len + 1 ))) return TRUE; + if (!(xdg_config = malloc( len + 1 ))) + { + CloseHandle( file ); + return TRUE; + } if (!ReadFile( file, xdg_config, len, &xdg_config_len, NULL )) { free( xdg_config ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/5827
participants (2)
-
Ruslan Garipov -
Ruslan Garipov (@ruslangaripov)