From cd09d58351d80e31668be0ca3edc95c3d160b4af Mon Sep 17 00:00:00 2001 From: Sean Dilda Date: Wed, 17 Apr 2019 17:10:08 -0400 Subject: [PATCH] Add option for close_on_exit Added an option (close_on_exit) to only add the at_exit to close the connection if desired. To prevent breaking existing code relying on this, the option defaults to true (keeping existing functionality). Setting to false will prevent the at_exit from being added which will solve existing cases of memory leaks. Closes #154 Fixes #156 --- lib/rbvmomi/vim.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rbvmomi/vim.rb b/lib/rbvmomi/vim.rb index c80e6db0..6d36ee81 100644 --- a/lib/rbvmomi/vim.rb +++ b/lib/rbvmomi/vim.rb @@ -28,6 +28,7 @@ class VIM < Connection # @option opts [String] :path (/sdk) SDK endpoint path. # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr. # @option opts [String] :operation_id If set, use for operationID + # @option opts [Boolean] :close_on_exit (true) If true, will close connection with at_exit def self.connect opts fail unless opts.is_a? Hash fail "host option required" unless opts[:host] @@ -64,7 +65,7 @@ def self.connect opts vim.rev = [rev, opts[:rev]].min { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) } end - at_exit { conn.close } + at_exit { conn.close } if opts.fetch(:close_on_exit, true) conn end