fix close/finalize

This commit is contained in:
Doug MacEachern 2004-11-22 06:09:47 +00:00
parent 8105d3c8f5
commit 9b111665f1
2 changed files with 6 additions and 3 deletions

View File

@ -43,7 +43,10 @@ public class RegistryKey extends Win32Bindings
public void close()
{
RegCloseKey(this.m_hkey);
if (this.m_hkey != 0) {
RegCloseKey(this.m_hkey);
this.m_hkey = 0;
}
}
public RegistryKey createSubKey(String subkey)
@ -223,8 +226,7 @@ public class RegistryKey extends Win32Bindings
protected void finalize()
{
if(this.m_hkey != 0)
this.close();
close();
}
private static final native int RegCloseKey(long hkey);

View File

@ -16,6 +16,7 @@ public class TestRegistryKey extends TestCase {
RegistryKey.LocalMachine.openSubKey("SOFTWARE");
String[] keys = software.getSubKeyNames();
assertTrue(keys.length > 0);
software.close();
}
//dont want to be writing to the registry