From 0a1bc9b59aeefac335dbd7e7763112ea91fb2e38 Mon Sep 17 00:00:00 2001 From: krazyest Date: Fri, 2 Nov 2012 10:13:56 +0100 Subject: [PATCH] Update TSRM/tsrm_win32.c This update fixes the handle leak described here - https://bugs.php.net/bug.php?id=62444 We have to initialize the local thread_token variable to prevent closing some 'random' handle. And at the end of the function we have to use CloseHandle to free the resources we might have obtained, to prevent the leak. --- TSRM/tsrm_win32.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index b40af77c44fc7..3e33935986c14 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -193,7 +193,7 @@ PSID tsrm_win32_get_token_sid(HANDLE hToken) TSRM_API int tsrm_win32_access(const char *pathname, int mode TSRMLS_DC) { time_t t; - HANDLE thread_token; + HANDLE thread_token = NULL; PSID token_sid; SECURITY_INFORMATION sec_info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION; GENERIC_MAPPING gen_map = { FILE_GENERIC_READ, FILE_GENERIC_WRITE, FILE_GENERIC_EXECUTE, FILE_ALL_ACCESS }; @@ -363,6 +363,10 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode TSRMLS_DC) } Finished: + if(thread_token != NULL) { + CloseHandle(thread_token); + } + if(real_path != NULL) { free(real_path); real_path = NULL;