From 616033d415610c09e72e9d9dfd6b8bf9f8faed87 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 21 Sep 2015 13:55:11 +0200 Subject: [PATCH] git-extra (WhoUses): auto-grow the buffer for the system information Without this, `WhoUses.exe` can fail with a "No handle information" with a large number of running processes. Signed-off-by: Johannes Schindelin --- git-extra/sources/SystemInfo.cpp | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/git-extra/sources/SystemInfo.cpp b/git-extra/sources/SystemInfo.cpp index 843802b..2579f5d 100644 --- a/git-extra/sources/SystemInfo.cpp +++ b/git-extra/sources/SystemInfo.cpp @@ -452,15 +452,20 @@ BOOL SystemHandleInformation::Refresh() (SYSTEM_HANDLE_INFORMATION*) VirtualAlloc( NULL, size, MEM_COMMIT, PAGE_READWRITE ); - if ( pSysHandleInformation == NULL ) - return FALSE; + while ( 1 ) { + if ( pSysHandleInformation == NULL ) + return FALSE; - // Query the needed buffer size for the objects ( system wide ) - if ( INtDll::NtQuerySystemInformation( 16, pSysHandleInformation, - size, &needed ) != 0 ) - { - if ( needed == 0 ) + // Query the needed buffer size for the objects ( system wide ) + DWORD result = INtDll::NtQuerySystemInformation( 16, + pSysHandleInformation, size, &needed ); + if ( result == 0 ) + break; + + if ( result != STATUS_INFO_LENGTH_MISMATCH ) { + fprintf( stderr, "NtQuerySystemInformation: 0x%x\n", + result ); ret = FALSE; goto cleanup; } @@ -473,17 +478,6 @@ BOOL SystemHandleInformation::Refresh() MEM_COMMIT, PAGE_READWRITE ); } - if ( pSysHandleInformation == NULL ) - return FALSE; - - // Query the objects ( system wide ) - if ( INtDll::NtQuerySystemInformation( 16, pSysHandleInformation, - size, NULL ) != 0 ) - { - ret = FALSE; - goto cleanup; - } - // Iterating through the objects for ( i = 0; i < pSysHandleInformation->Count; i++ ) {