[前][次][番号順一覧][スレッド一覧]

ruby-changes:60065

From: Nobuyoshi <ko1@a...>
Date: Thu, 13 Feb 2020 15:23:46 +0900 (JST)
Subject: [ruby-changes:60065] 95ab9cd8f4 (ruby_2_7): Restart timer thread even after preparation failed

https://git.ruby-lang.org/ruby.git/commit/?id=95ab9cd8f4

From 95ab9cd8f453099d7649dc0e0eec55ea891340f5 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 11 Feb 2020 15:52:25 +0900
Subject: Restart timer thread even after preparation failed

If the timer thread is left stopped, memory crash or segfault can
happen. [Bug #16624]

diff --git a/process.c b/process.c
index 3ea6eb2..530f320 100644
--- a/process.c
+++ b/process.c
@@ -2885,13 +2885,20 @@ rb_f_exec(int argc, const VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L2885
     struct rb_execarg *eargp;
 #define CHILD_ERRMSG_BUFLEN 80
     char errmsg[CHILD_ERRMSG_BUFLEN] = { '\0' };
-    int err;
+    int err, state;
 
     execarg_obj = rb_execarg_new(argc, argv, TRUE, FALSE);
     eargp = rb_execarg_get(execarg_obj);
     if (mjit_enabled) mjit_finish(false); // avoid leaking resources, and do not leave files. XXX: JIT-ed handle can leak after exec error is rescued.
     before_exec(); /* stop timer thread before redirects */
-    rb_execarg_parent_start(execarg_obj);
+
+    rb_protect(rb_execarg_parent_start1, execarg_obj, &state);
+    if (state) {
+        execarg_parent_end(execarg_obj);
+        after_exec(); /* restart timer thread */
+        rb_jump_tag(state);
+    }
+
     fail_str = eargp->use_shell ? eargp->invoke.sh.shell_script : eargp->invoke.cmd.command_name;
 
     err = exec_async_signal_safe(eargp, errmsg, sizeof(errmsg));
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index e0cb49b..ab723c6 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -2399,6 +2399,15 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L2399
     r.close if r
   end if defined?(fork)
 
+  def test_rescue_exec_fail
+    assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+    begin;
+      assert_raise(Errno::ENOENT) do
+        exec("", in: "")
+      end
+    end;
+  end
+
   def test_many_args
     bug11418 = '[ruby-core:70251] [Bug #11418]'
     assert_in_out_err([], <<-"end;", ["x"]*256, [], bug11418, timeout: 60)
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]