mirror of https://github.com/OpenVPN/openvpn-gui
Close registry keys after use
- Open registry key HKCU was not closed in some code paths - Also fix incorrect return value checks in GetRegistryKeys() and SetRegistryVersion() Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/162/head
parent
225df6a756
commit
3513fb9220
20
registry.c
20
registry.c
|
@ -174,7 +174,7 @@ GetRegistryKeys ()
|
|||
PrintDebug(L"from registry: %s = %lu", regkey_int[i].name, *regkey_int[i].var);
|
||||
}
|
||||
|
||||
if ( status != ERROR_SUCCESS)
|
||||
if ( status == ERROR_SUCCESS)
|
||||
RegCloseKey (regkey);
|
||||
|
||||
if ((o.disconnectscript_timeout == 0))
|
||||
|
@ -198,13 +198,14 @@ SaveRegistryKeys ()
|
|||
HKEY regkey;
|
||||
DWORD status;
|
||||
int i;
|
||||
int ret = false;
|
||||
|
||||
status = RegCreateKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, NULL, REG_OPTION_NON_VOLATILE,
|
||||
KEY_WRITE|KEY_READ, NULL, ®key, NULL);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
ShowLocalizedMsg (IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU);
|
||||
return false;
|
||||
goto out;
|
||||
}
|
||||
for (i = 0 ; i < (int) _countof (regkey_str); ++i)
|
||||
{
|
||||
|
@ -213,7 +214,7 @@ SaveRegistryKeys ()
|
|||
RegValueExists(regkey, regkey_str[i].name) )
|
||||
{
|
||||
if (!SetRegistryValue (regkey, regkey_str[i].name, regkey_str[i].var))
|
||||
return false;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,13 +224,16 @@ SaveRegistryKeys ()
|
|||
RegValueExists(regkey, regkey_int[i].name) )
|
||||
{
|
||||
if (!SetRegistryValueNumeric (regkey, regkey_int[i].name, *regkey_int[i].var))
|
||||
return false;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
ret = true;
|
||||
|
||||
out:
|
||||
|
||||
if (status == ERROR_SUCCESS)
|
||||
RegCloseKey(regkey);
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
|
@ -260,8 +264,8 @@ SetRegistryVersion (const version_t *v)
|
|||
KEY_WRITE, NULL, ®key, NULL);
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
ret = (RegSetValueEx(regkey, L"version", 0, REG_BINARY, (const BYTE*) v, sizeof(*v))
|
||||
!= ERROR_SUCCESS);
|
||||
if (RegSetValueEx(regkey, L"version", 0, REG_BINARY, (const BYTE*) v, sizeof(*v)) == ERROR_SUCCESS)
|
||||
ret = true;
|
||||
RegCloseKey(regkey);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue