Add same fix as to lib/mruby/gem.rb .
MODIFY
lib/mruby/gem.rb
lib/mruby/gem.rb
@@ -176,6 +176,7 @@ module MRuby
f.puts %Q[ mrb_load_irep(mrb, gem_mrblib_irep_#{funcname});]
f.puts %Q[ if (mrb->exc) {]
f.puts %Q[ mrb_print_error(mrb);]
+ f.puts %Q[ mrb_close(mrb);]
f.puts %Q[ exit(EXIT_FAILURE);]
f.puts %Q[ }]
end

Add same fix as #3964 to lib/mruby/gem.rb .