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
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");

View file

@ -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;

View file

@ -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)

View file

@ -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;
}