summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/ruby/test_thread.rb11
-rw-r--r--thread.c1
-rw-r--r--thread_sync.c14
-rw-r--r--version.h2
4 files changed, 27 insertions, 1 deletions
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index 591292962d..135d17237e 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -1188,6 +1188,17 @@ q.pop
assert_predicate(status, :success?, bug9751)
end if Process.respond_to?(:fork)
+ def test_fork_while_locked
+ m = Mutex.new
+ thrs = []
+ 3.times do |i|
+ thrs << Thread.new { m.synchronize { Process.waitpid2(fork{})[1] } }
+ end
+ thrs.each do |t|
+ assert_predicate t.value, :success?, '[ruby-core:85940] [Bug #14578]'
+ end
+ end if Process.respond_to?(:fork)
+
def test_subclass_no_initialize
t = Module.new do
break eval("class C\u{30b9 30ec 30c3 30c9} < Thread; self; end")
diff --git a/thread.c b/thread.c
index 9f2267a1f4..fad0ce6efc 100644
--- a/thread.c
+++ b/thread.c
@@ -4208,6 +4208,7 @@ rb_thread_atfork(void)
rb_thread_t *th = GET_THREAD();
rb_thread_atfork_internal(th, terminate_atfork_i);
th->join_list = NULL;
+ rb_mutex_cleanup_keeping_mutexes(th);
/* We don't want reproduce CVE-2003-0900. */
rb_reset_random_seed();
diff --git a/thread_sync.c b/thread_sync.c
index b4970e507c..ef0bbf3af3 100644
--- a/thread_sync.c
+++ b/thread_sync.c
@@ -415,6 +415,20 @@ rb_mutex_abandon_all(rb_mutex_t *mutexes)
list_head_init(&mutex->waitq);
}
}
+
+/*
+ * All other threads are dead in the a new child process, so waitqs
+ * contain references to dead threads which we need to clean up
+ */
+static void
+rb_mutex_cleanup_keeping_mutexes(const rb_thread_t *current_thread)
+{
+ rb_mutex_t *mutex = current_thread->keeping_mutexes;
+ while (mutex) {
+ list_head_init(&mutex->waitq);
+ mutex = mutex->next_mutex;
+ }
+}
#endif
static VALUE
diff --git a/version.h b/version.h
index 33fb4e79ee..0a58882496 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.5.0"
#define RUBY_RELEASE_DATE "2018-03-19"
-#define RUBY_PATCHLEVEL 42
+#define RUBY_PATCHLEVEL 43
#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 3