From f7f1ca09ede03d83765c95359f7907f90a22a8d3 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 14 Aug 2024 14:09:17 +1000 Subject: [PATCH] FIX: skip mini_racer_loader when malloc is overridden 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: https://github.com/rubyjs/mini_racer/issues/292#issuecomment-1835646792 --- lib/mini_racer.rb | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/mini_racer.rb b/lib/mini_racer.rb index 7f4a0d7c..e615a4d9 100644 --- a/lib/mini_racer.rb +++ b/lib/mini_racer.rb @@ -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"