summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chef/lib/chef/win32/api/process.rb1
-rw-r--r--chef/lib/chef/win32/handle.rb9
2 files changed, 9 insertions, 1 deletions
diff --git a/chef/lib/chef/win32/api/process.rb b/chef/lib/chef/win32/api/process.rb
index d18ad411b4..0aca992ed5 100644
--- a/chef/lib/chef/win32/api/process.rb
+++ b/chef/lib/chef/win32/api/process.rb
@@ -33,6 +33,7 @@ class Chef
safe_attach_function :GetCurrentProcess, [], :HANDLE
safe_attach_function :GetProcessHandleCount, [ :HANDLE, :LPDWORD ], :BOOL
safe_attach_function :GetProcessId, [ :HANDLE ], :DWORD
+ safe_attach_function :CloseHandle, [ :HANDLE ], :BOOL
end
end
diff --git a/chef/lib/chef/win32/handle.rb b/chef/lib/chef/win32/handle.rb
index 60e35916ad..3e92703db9 100644
--- a/chef/lib/chef/win32/handle.rb
+++ b/chef/lib/chef/win32/handle.rb
@@ -26,6 +26,10 @@ class Chef
class Handle
extend Chef::ReservedNames::Win32::API::Process
+ # See http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx
+ # The handle value returned by the GetCurrentProcess function is the pseudo handle (HANDLE)-1 (which is 0xFFFFFFFF)
+ CURRENT_PROCESS_HANDLE = 4294967295
+
def initialize(handle)
@handle = handle
ObjectSpace.define_finalizer(self, Handle.close_handle_finalizer(handle))
@@ -34,7 +38,10 @@ class Chef
attr_reader :handle
def self.close_handle_finalizer(handle)
- proc { close_handle(handle) }
+ # According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx, it is not necessary
+ # to close the pseudo handle returned by the GetCurrentProcess function. The docs also say that it doesn't hurt to call
+ # CloseHandle on it. However, doing so from inside of Ruby always seems to produce an invalid handle error.
+ proc { close_handle(handle) unless handle == CURRENT_PROCESS_HANDLE }
end
def self.close_handle(handle)