File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,7 @@ psutil_get_open_files(DWORD dwPid, HANDLE hProcess) {
193193 PSYSTEM_HANDLE_INFORMATION_EX handlesList = NULL ;
194194 PSYSTEM_HANDLE_TABLE_ENTRY_INFO_EX hHandle = NULL ;
195195 HANDLE hFile = NULL ;
196+ HANDLE hSafeFile = NULL ;
196197 ULONG i = 0 ;
197198 BOOLEAN errorOccurred = FALSE;
198199 PyObject * py_path = NULL ;
@@ -222,14 +223,17 @@ psutil_get_open_files(DWORD dwPid, HANDLE hProcess) {
222223 continue ;
223224 }
224225
225- if (GetFileType (hFile ) != FILE_TYPE_DISK ) {
226- SetLastError (0 );
227- CloseHandle (hFile );
228- hFile = NULL ;
226+ hSafeFile = ReOpenFile (
227+ hFile ,
228+ 0 ,
229+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
230+ 0 );
231+ CloseHandle (hFile );
232+
233+ if (hSafeFile == INVALID_HANDLE_VALUE )
229234 continue ;
230- }
231235
232- fileName = psutil_threaded_get_filename (hFile );
236+ fileName = psutil_threaded_get_filename (hSafeFile );
233237 if (fileName == NULL )
234238 goto error ;
235239
@@ -248,8 +252,8 @@ psutil_get_open_files(DWORD dwPid, HANDLE hProcess) {
248252 FREE (fileName );
249253 fileName = NULL ;
250254 }
251- CloseHandle (hFile );
252- hFile = NULL ;
255+ CloseHandle (hSafeFile );
256+ hSafeFile = NULL ;
253257 }
254258
255259 goto exit ;
@@ -260,8 +264,8 @@ psutil_get_open_files(DWORD dwPid, HANDLE hProcess) {
260264 goto exit ;
261265
262266exit :
263- if (hFile != NULL )
264- CloseHandle (hFile );
267+ if (hSafeFile != NULL )
268+ CloseHandle (hSafeFile );
265269 if (fileName != NULL )
266270 FREE (fileName );
267271 if (py_path != NULL )
You can’t perform that action at this time.
0 commit comments