diff --git a/libinterp/corefcn/sysdep.cc b/libinterp/corefcn/sysdep.cc --- a/libinterp/corefcn/sysdep.cc +++ b/libinterp/corefcn/sysdep.cc @@ -713,6 +713,13 @@ occurred. */ #if defined (OCTAVE_USE_WINDOWS_API) + +static void +reg_close_key (HKEY key) +{ + RegCloseKey (key); +} + LONG get_regkey_value (HKEY h_rootkey, const std::string subkey, const std::string name, octave_value& value) @@ -724,6 +731,10 @@ get_regkey_value (HKEY h_rootkey, const if (result != ERROR_SUCCESS) return result; + octave::unwind_protect frame; + + frame.add_fcn (reg_close_key, h_subkey); + DWORD length = 0; result = RegQueryValueExA (h_subkey, name.c_str (), nullptr, nullptr, nullptr, &length);