Skip to content

Commit 421f47c

Browse files
committed
Avoid capturing local variables referencing the pre-initialization home in blocks
(cherry picked from commit 97d4413)
1 parent 697963f commit 421f47c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/main/ruby/truffleruby/core/post.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,18 @@ def p(*a)
105105
ARGV.concat(Truffle::Boot.original_argv)
106106
end
107107

108-
ruby_home = Truffle::Boot.ruby_home
109-
if ruby_home
110-
# Does not exist but it's used by rubygems to determine index where to insert gem lib directories, as a result
111-
# paths supplied by -I will stay before gem lib directories. See Gem.load_path_insert_index in rubygems.rb.
112-
# Must be kept in sync with the value of RbConfig::CONFIG['sitelibdir'].
113-
$LOAD_PATH.push "#{ruby_home}/lib/ruby/site_ruby/#{RUBY_ENGINE_VERSION}"
114-
115-
$LOAD_PATH.push "#{ruby_home}/lib/truffle"
116-
$LOAD_PATH.push "#{ruby_home}/lib/mri"
117-
$LOAD_PATH.push "#{ruby_home}/lib/json/lib"
108+
yield_self do # Avoid capturing ruby_home in the at_exit and delay blocks
109+
ruby_home = Truffle::Boot.ruby_home
110+
if ruby_home
111+
# Does not exist but it's used by rubygems to determine index where to insert gem lib directories, as a result
112+
# paths supplied by -I will stay before gem lib directories. See Gem.load_path_insert_index in rubygems.rb.
113+
# Must be kept in sync with the value of RbConfig::CONFIG['sitelibdir'].
114+
$LOAD_PATH.push "#{ruby_home}/lib/ruby/site_ruby/#{RUBY_ENGINE_VERSION}"
115+
116+
$LOAD_PATH.push "#{ruby_home}/lib/truffle"
117+
$LOAD_PATH.push "#{ruby_home}/lib/mri"
118+
$LOAD_PATH.push "#{ruby_home}/lib/json/lib"
119+
end
118120
end
119121

120122
Truffle::Boot.delay do

src/main/ruby/truffleruby/post-boot/post-boot.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
end
8484
end
8585
end
86-
old_home = nil
86+
old_home = nil # Avoid capturing the old home in the blocks below
8787

8888
Truffle::Boot.delay do
8989
new_home = Truffle::Boot.ruby_home

0 commit comments

Comments
 (0)