From 9b111665f11de6ed36574e79f835f0c54e572faf Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 22 Nov 2004 06:09:47 +0000 Subject: [PATCH] fix close/finalize --- .../java/src/net/hyperic/sigar/win32/RegistryKey.java | 8 +++++--- .../src/net/hyperic/sigar/win32/test/TestRegistryKey.java | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bindings/java/src/net/hyperic/sigar/win32/RegistryKey.java b/bindings/java/src/net/hyperic/sigar/win32/RegistryKey.java index c4e06eb3..35fda300 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/RegistryKey.java +++ b/bindings/java/src/net/hyperic/sigar/win32/RegistryKey.java @@ -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); diff --git a/bindings/java/src/net/hyperic/sigar/win32/test/TestRegistryKey.java b/bindings/java/src/net/hyperic/sigar/win32/test/TestRegistryKey.java index 73272d0b..1becf84b 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/test/TestRegistryKey.java +++ b/bindings/java/src/net/hyperic/sigar/win32/test/TestRegistryKey.java @@ -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