fix apps depending on INVALID_HANDLE_VALUE

bug report & patch by w3seek

svn path=/trunk/; revision=22179
This commit is contained in:
Johannes Anderwald 2006-06-02 14:37:25 +00:00
parent 449a2042e7
commit 01c01fafcd
4 changed files with 30 additions and 26 deletions

View file

@ -1169,7 +1169,7 @@ cleanup:
static BOOL static BOOL
SetupIsActive(VOID) SetupIsActive(VOID)
{ {
HKEY hKey = INVALID_HANDLE_VALUE; HKEY hKey = NULL;
DWORD regType, active, size; DWORD regType, active, size;
LONG rc; LONG rc;
BOOL ret = FALSE; BOOL ret = FALSE;
@ -1188,7 +1188,7 @@ SetupIsActive(VOID)
ret = (active != 0); ret = (active != 0);
cleanup: cleanup:
if (hKey != INVALID_HANDLE_VALUE) if (hKey != NULL)
RegCloseKey(hKey); RegCloseKey(hKey);
DPRINT("System setup in progress? %S\n", ret ? L"YES" : L"NO"); DPRINT("System setup in progress? %S\n", ret ? L"YES" : L"NO");

View file

@ -24,11 +24,11 @@ DisplayClassInstaller(
TCHAR SectionName[MAX_PATH]; TCHAR SectionName[MAX_PATH];
TCHAR ServiceName[MAX_SERVICE_NAME_LEN]; TCHAR ServiceName[MAX_SERVICE_NAME_LEN];
SP_DRVINFO_DETAIL_DATA DriverInfoDetailData; SP_DRVINFO_DETAIL_DATA DriverInfoDetailData;
HKEY hDriverKey = INVALID_HANDLE_VALUE; HKEY hDriverKey = INVALID_HANDLE_VALUE; /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
HKEY hSettingsKey = INVALID_HANDLE_VALUE; HKEY hSettingsKey = NULL;
HKEY hServicesKey = INVALID_HANDLE_VALUE; HKEY hServicesKey = NULL;
HKEY hServiceKey = INVALID_HANDLE_VALUE; HKEY hServiceKey = NULL;
HKEY hDeviceSubKey = INVALID_HANDLE_VALUE; HKEY hDeviceSubKey = NULL;
DWORD disposition; DWORD disposition;
BOOL result; BOOL result;
LONG rc; LONG rc;
@ -214,14 +214,17 @@ cleanup:
if (hInf != INVALID_HANDLE_VALUE) if (hInf != INVALID_HANDLE_VALUE)
SetupCloseInfFile(hInf); SetupCloseInfFile(hInf);
if (hDriverKey != INVALID_HANDLE_VALUE) if (hDriverKey != INVALID_HANDLE_VALUE)
{
/* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
RegCloseKey(hDriverKey); RegCloseKey(hDriverKey);
if (hSettingsKey != INVALID_HANDLE_VALUE) }
if (hSettingsKey != NULL)
RegCloseKey(hSettingsKey); RegCloseKey(hSettingsKey);
if (hServicesKey != INVALID_HANDLE_VALUE) if (hServicesKey != NULL)
RegCloseKey(hServicesKey); RegCloseKey(hServicesKey);
if (hServiceKey != INVALID_HANDLE_VALUE) if (hServiceKey != NULL)
RegCloseKey(hServiceKey); RegCloseKey(hServiceKey);
if (hDeviceSubKey != INVALID_HANDLE_VALUE) if (hDeviceSubKey != NULL)
RegCloseKey(hDeviceSubKey); RegCloseKey(hDeviceSubKey);
return rc; return rc;

View file

@ -184,10 +184,10 @@ NetClassInstaller(
LPWSTR ExportName = NULL; LPWSTR ExportName = NULL;
LONG rc; LONG rc;
DWORD dwShowIcon, dwLength; DWORD dwShowIcon, dwLength;
HKEY hKey = INVALID_HANDLE_VALUE; HKEY hKey = NULL;
HKEY hLinkageKey = INVALID_HANDLE_VALUE; HKEY hLinkageKey = NULL;
HKEY hNetworkKey = INVALID_HANDLE_VALUE; HKEY hNetworkKey = NULL;
HKEY hConnectionKey = INVALID_HANDLE_VALUE; HKEY hConnectionKey = NULL;
if (InstallFunction != DIF_INSTALLDEVICE) if (InstallFunction != DIF_INSTALLDEVICE)
return ERROR_DI_DO_DEFAULT; return ERROR_DI_DO_DEFAULT;
@ -279,7 +279,7 @@ NetClassInstaller(
goto cleanup; goto cleanup;
} }
RegCloseKey(hKey); 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); rc = RegCreateKeyExW(hNetworkKey, L"Parameters\\Tcpip", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL);
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
@ -287,7 +287,7 @@ NetClassInstaller(
goto cleanup; goto cleanup;
} }
RegCloseKey(hNetworkKey); 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)); 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) if (rc != ERROR_SUCCESS)
{ {
@ -307,7 +307,7 @@ NetClassInstaller(
goto cleanup; goto cleanup;
} }
RegCloseKey(hKey); RegCloseKey(hKey);
hKey = INVALID_HANDLE_VALUE; hKey = NULL;
/* Write 'Linkage' key in hardware key */ /* Write 'Linkage' key in hardware key */
#if _WIN32_WINNT >= 0x502 #if _WIN32_WINNT >= 0x502
@ -319,6 +319,7 @@ NetClassInstaller(
hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, NULL, NULL); hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, NULL, NULL);
if (hKey == INVALID_HANDLE_VALUE) if (hKey == INVALID_HANDLE_VALUE)
{ {
hKey = NULL;
rc = GetLastError(); rc = GetLastError();
DPRINT("SetupDiCreateDevRegKeyW() failed with error 0x%lx\n", rc); DPRINT("SetupDiCreateDevRegKeyW() failed with error 0x%lx\n", rc);
goto cleanup; goto cleanup;
@ -354,7 +355,7 @@ NetClassInstaller(
goto cleanup; goto cleanup;
} }
RegCloseKey(hKey); RegCloseKey(hKey);
hKey = INVALID_HANDLE_VALUE; hKey = NULL;
/* Write connection information in network subkey */ /* 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); 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); rc = RegCreateKeyExW(hKey, L"Connection", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hConnectionKey, NULL);
RegCloseKey(hKey); RegCloseKey(hKey);
hKey = INVALID_HANDLE_VALUE; hKey = NULL;
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc); DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
@ -446,13 +447,13 @@ cleanup:
HeapFree(GetProcessHeap(), 0, UuidString); HeapFree(GetProcessHeap(), 0, UuidString);
HeapFree(GetProcessHeap(), 0, DeviceName); HeapFree(GetProcessHeap(), 0, DeviceName);
HeapFree(GetProcessHeap(), 0, ExportName); HeapFree(GetProcessHeap(), 0, ExportName);
if (hKey != INVALID_HANDLE_VALUE) if (hKey != NULL)
RegCloseKey(hKey); RegCloseKey(hKey);
if (hLinkageKey != INVALID_HANDLE_VALUE) if (hLinkageKey != NULL)
RegCloseKey(hLinkageKey); RegCloseKey(hLinkageKey);
if (hNetworkKey != INVALID_HANDLE_VALUE) if (hNetworkKey != NULL)
RegCloseKey(hNetworkKey); RegCloseKey(hNetworkKey);
if (hConnectionKey != INVALID_HANDLE_VALUE) if (hConnectionKey != NULL)
RegCloseKey(hConnectionKey); RegCloseKey(hConnectionKey);
if (rc == ERROR_SUCCESS) if (rc == ERROR_SUCCESS)

View file

@ -1317,7 +1317,7 @@ IopGetParentIdPrefix(PDEVICE_NODE DeviceNode,
UNICODE_STRING KeyValue; UNICODE_STRING KeyValue;
UNICODE_STRING ValueName; UNICODE_STRING ValueName;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE hKey = INVALID_HANDLE_VALUE; HANDLE hKey = NULL;
ULONG crc32; ULONG crc32;
NTSTATUS Status; NTSTATUS Status;
@ -1395,7 +1395,7 @@ cleanup:
} }
ExFreePool(ParentIdPrefixInformation); ExFreePool(ParentIdPrefixInformation);
ExFreePool(KeyNameBuffer); ExFreePool(KeyNameBuffer);
if (hKey != INVALID_HANDLE_VALUE) if (hKey != NULL)
ZwClose(hKey); ZwClose(hKey);
return Status; return Status;
} }