From 01c01fafcd73b44eee2a259343b4320421b9fe0d Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Fri, 2 Jun 2006 14:37:25 +0000 Subject: [PATCH] fix apps depending on INVALID_HANDLE_VALUE bug report & patch by w3seek svn path=/trunk/; revision=22179 --- reactos/base/services/umpnpmgr/umpnpmgr.c | 4 ++-- reactos/dll/cpl/desk/classinst.c | 21 ++++++++++-------- reactos/dll/win32/netcfgx/netcfgx.c | 27 ++++++++++++----------- reactos/ntoskrnl/io/pnpmgr.c | 4 ++-- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/reactos/base/services/umpnpmgr/umpnpmgr.c b/reactos/base/services/umpnpmgr/umpnpmgr.c index 4cd0cb4b7bf..0c60b8db6c8 100644 --- a/reactos/base/services/umpnpmgr/umpnpmgr.c +++ b/reactos/base/services/umpnpmgr/umpnpmgr.c @@ -1169,7 +1169,7 @@ cleanup: static BOOL SetupIsActive(VOID) { - HKEY hKey = INVALID_HANDLE_VALUE; + HKEY hKey = NULL; DWORD regType, active, size; LONG rc; BOOL ret = FALSE; @@ -1188,7 +1188,7 @@ SetupIsActive(VOID) ret = (active != 0); cleanup: - if (hKey != INVALID_HANDLE_VALUE) + if (hKey != NULL) RegCloseKey(hKey); DPRINT("System setup in progress? %S\n", ret ? L"YES" : L"NO"); diff --git a/reactos/dll/cpl/desk/classinst.c b/reactos/dll/cpl/desk/classinst.c index 1221925d3c4..60035246293 100644 --- a/reactos/dll/cpl/desk/classinst.c +++ b/reactos/dll/cpl/desk/classinst.c @@ -24,11 +24,11 @@ DisplayClassInstaller( TCHAR SectionName[MAX_PATH]; TCHAR ServiceName[MAX_SERVICE_NAME_LEN]; SP_DRVINFO_DETAIL_DATA DriverInfoDetailData; - HKEY hDriverKey = INVALID_HANDLE_VALUE; - HKEY hSettingsKey = INVALID_HANDLE_VALUE; - HKEY hServicesKey = INVALID_HANDLE_VALUE; - HKEY hServiceKey = INVALID_HANDLE_VALUE; - HKEY hDeviceSubKey = INVALID_HANDLE_VALUE; + HKEY hDriverKey = INVALID_HANDLE_VALUE; /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */ + HKEY hSettingsKey = NULL; + HKEY hServicesKey = NULL; + HKEY hServiceKey = NULL; + HKEY hDeviceSubKey = NULL; DWORD disposition; BOOL result; LONG rc; @@ -214,14 +214,17 @@ cleanup: if (hInf != INVALID_HANDLE_VALUE) SetupCloseInfFile(hInf); if (hDriverKey != INVALID_HANDLE_VALUE) + { + /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */ RegCloseKey(hDriverKey); - if (hSettingsKey != INVALID_HANDLE_VALUE) + } + if (hSettingsKey != NULL) RegCloseKey(hSettingsKey); - if (hServicesKey != INVALID_HANDLE_VALUE) + if (hServicesKey != NULL) RegCloseKey(hServicesKey); - if (hServiceKey != INVALID_HANDLE_VALUE) + if (hServiceKey != NULL) RegCloseKey(hServiceKey); - if (hDeviceSubKey != INVALID_HANDLE_VALUE) + if (hDeviceSubKey != NULL) RegCloseKey(hDeviceSubKey); return rc; diff --git a/reactos/dll/win32/netcfgx/netcfgx.c b/reactos/dll/win32/netcfgx/netcfgx.c index 215d364c272..ee03c28360e 100644 --- a/reactos/dll/win32/netcfgx/netcfgx.c +++ b/reactos/dll/win32/netcfgx/netcfgx.c @@ -184,10 +184,10 @@ NetClassInstaller( LPWSTR ExportName = NULL; LONG rc; DWORD dwShowIcon, dwLength; - HKEY hKey = INVALID_HANDLE_VALUE; - HKEY hLinkageKey = INVALID_HANDLE_VALUE; - HKEY hNetworkKey = INVALID_HANDLE_VALUE; - HKEY hConnectionKey = INVALID_HANDLE_VALUE; + HKEY hKey = NULL; + HKEY hLinkageKey = NULL; + HKEY hNetworkKey = NULL; + HKEY hConnectionKey = NULL; if (InstallFunction != DIF_INSTALLDEVICE) return ERROR_DI_DO_DEFAULT; @@ -279,7 +279,7 @@ NetClassInstaller( goto cleanup; } RegCloseKey(hKey); - hKey = INVALID_HANDLE_VALUE; + hKey = NULL; rc = RegCreateKeyExW(hNetworkKey, L"Parameters\\Tcpip", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL); if (rc != ERROR_SUCCESS) { @@ -287,7 +287,7 @@ NetClassInstaller( goto cleanup; } RegCloseKey(hNetworkKey); - hNetworkKey = INVALID_HANDLE_VALUE; + hNetworkKey = NULL; rc = RegSetValueExW(hKey, L"DefaultGateway", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR)); if (rc != ERROR_SUCCESS) { @@ -307,7 +307,7 @@ NetClassInstaller( goto cleanup; } RegCloseKey(hKey); - hKey = INVALID_HANDLE_VALUE; + hKey = NULL; /* Write 'Linkage' key in hardware key */ #if _WIN32_WINNT >= 0x502 @@ -319,6 +319,7 @@ NetClassInstaller( hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, NULL, NULL); if (hKey == INVALID_HANDLE_VALUE) { + hKey = NULL; rc = GetLastError(); DPRINT("SetupDiCreateDevRegKeyW() failed with error 0x%lx\n", rc); goto cleanup; @@ -354,7 +355,7 @@ NetClassInstaller( goto cleanup; } RegCloseKey(hKey); - hKey = INVALID_HANDLE_VALUE; + hKey = NULL; /* Write connection information in network subkey */ rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hNetworkKey, NULL); @@ -371,7 +372,7 @@ NetClassInstaller( } rc = RegCreateKeyExW(hKey, L"Connection", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hConnectionKey, NULL); RegCloseKey(hKey); - hKey = INVALID_HANDLE_VALUE; + hKey = NULL; if (rc != ERROR_SUCCESS) { DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc); @@ -446,13 +447,13 @@ cleanup: HeapFree(GetProcessHeap(), 0, UuidString); HeapFree(GetProcessHeap(), 0, DeviceName); HeapFree(GetProcessHeap(), 0, ExportName); - if (hKey != INVALID_HANDLE_VALUE) + if (hKey != NULL) RegCloseKey(hKey); - if (hLinkageKey != INVALID_HANDLE_VALUE) + if (hLinkageKey != NULL) RegCloseKey(hLinkageKey); - if (hNetworkKey != INVALID_HANDLE_VALUE) + if (hNetworkKey != NULL) RegCloseKey(hNetworkKey); - if (hConnectionKey != INVALID_HANDLE_VALUE) + if (hConnectionKey != NULL) RegCloseKey(hConnectionKey); if (rc == ERROR_SUCCESS) diff --git a/reactos/ntoskrnl/io/pnpmgr.c b/reactos/ntoskrnl/io/pnpmgr.c index a10790a1546..d3eb0a6cb43 100644 --- a/reactos/ntoskrnl/io/pnpmgr.c +++ b/reactos/ntoskrnl/io/pnpmgr.c @@ -1317,7 +1317,7 @@ IopGetParentIdPrefix(PDEVICE_NODE DeviceNode, UNICODE_STRING KeyValue; UNICODE_STRING ValueName; OBJECT_ATTRIBUTES ObjectAttributes; - HANDLE hKey = INVALID_HANDLE_VALUE; + HANDLE hKey = NULL; ULONG crc32; NTSTATUS Status; @@ -1395,7 +1395,7 @@ cleanup: } ExFreePool(ParentIdPrefixInformation); ExFreePool(KeyNameBuffer); - if (hKey != INVALID_HANDLE_VALUE) + if (hKey != NULL) ZwClose(hKey); return Status; }