Skip to content

Commit

Permalink
FIX: skip mini_racer_loader when malloc is overridden
Browse files Browse the repository at this point in the history
LD_PRELOAD can potentially cause issues with the "symbols hidden"
loader for mini_racer

This will unconditionally skip the loader when LD_PRELOAD is specified
and points to *malloc (eg jemalloc or tcmalloc)

see: #292 (comment)
  • Loading branch information
SamSaffron committed Aug 14, 2024
1 parent 537eae9 commit f7f1ca0
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/mini_racer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
if RUBY_ENGINE == "truffleruby"
require "mini_racer/truffleruby"
else
require "mini_racer_loader"
ext_filename = "mini_racer_extension.#{RbConfig::CONFIG['DLEXT']}"
ext_path = Gem.loaded_specs['mini_racer'].require_paths
.map { |p| (p = Pathname.new(p)).absolute? ? p : Pathname.new(__dir__).parent + p }
ext_found = ext_path.map { |p| p + ext_filename }.find { |p| p.file? }

raise LoadError, "Could not find #{ext_filename} in #{ext_path.map(&:to_s)}" unless ext_found
MiniRacer::Loader.load(ext_found.to_s)
if ENV["LD_PRELOAD"].to_s.include?("malloc")
require "mini_racer_extension"
else
require "mini_racer_loader"
ext_filename = "mini_racer_extension.#{RbConfig::CONFIG["DLEXT"]}"
ext_path =
Gem.loaded_specs["mini_racer"].require_paths.map do |p|
(p = Pathname.new(p)).absolute? ? p : Pathname.new(__dir__).parent + p
end
ext_found = ext_path.map { |p| p + ext_filename }.find { |p| p.file? }

unless ext_found
raise LoadError,
"Could not find #{ext_filename} in #{ext_path.map(&:to_s)}"
end
MiniRacer::Loader.load(ext_found.to_s)
end
end

require "thread"
Expand Down

0 comments on commit f7f1ca0

Please sign in to comment.