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

ruby-changes:59999

From: Nobuyoshi <ko1@a...>
Date: Tue, 11 Feb 2020 15:59:06 +0900 (JST)
Subject: [ruby-changes:59999] de3883e782 (master): Restart timer thread even after preparation failed

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

From de3883e7823c89ce90d7661ef5bb3b7eb60968db 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.

diff --git a/process.c b/process.c
index bb89515..725ab0d 100644
--- a/process.c
+++ b/process.c
@@ -2905,13 +2905,20 @@ rb_f_exec(int argc, const VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L2905
     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 115c33a..53599a6 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -2397,6 +2397,15 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L2397
     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/

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