summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-09 14:45:56 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-09 14:45:56 +0000
commit1fdbe0f437de59f87527818918b55d794a5fb92d (patch)
tree5debf417488a6637ce9fd12074e744fe24c73722
parent50a058b6beb55998b6d06b912bb8ffeb9131e6af (diff)
* gc.c (rb_objspace_call_finalizer): use rb_typeddata_is_kind_of() for
type check to get rid of a double free when main Thread has singleton class. [ruby-core:36741] [Bug #4828] * thread.c (rb_obj_is_mutex): add a new utility function. * vm.c (rb_obj_is_thread): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--gc.c2
-rw-r--r--internal.h3
-rw-r--r--thread.c11
-rw-r--r--vm.c11
5 files changed, 34 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4d513ac..f347f83 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Jun 9 23:34:01 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
+
+ * gc.c (rb_objspace_call_finalizer): use rb_typeddata_is_kind_of() for
+ type check to get rid of a double free when main Thread has singleton
+ class. [ruby-core:36741] [Bug #4828]
+ * thread.c (rb_obj_is_mutex): add a new utility function.
+ * vm.c (rb_obj_is_thread): ditto.
+
Thu Jun 9 22:53:49 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
* test/ruby/test_thread.rb (TestThread#test_kill_thread_subclass):
diff --git a/gc.c b/gc.c
index 28fa233..aab0963 100644
--- a/gc.c
+++ b/gc.c
@@ -3005,7 +3005,7 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
while (p < pend) {
if (BUILTIN_TYPE(p) == T_DATA &&
DATA_PTR(p) && RANY(p)->as.data.dfree &&
- RANY(p)->as.basic.klass != rb_cThread && RANY(p)->as.basic.klass != rb_cMutex) {
+ !rb_obj_is_thread((VALUE)p) && !rb_obj_is_mutex((VALUE)p) ) {
p->as.free.flags = 0;
if (RTYPEDDATA_P(p)) {
RDATA(p)->dfree = RANY(p)->as.typeddata.type->function.dfree;
diff --git a/internal.h b/internal.h
index 4e39e47..2ef1fc4 100644
--- a/internal.h
+++ b/internal.h
@@ -27,6 +27,9 @@ struct rb_classext_struct {
VALUE rb_big_uminus(VALUE x);
+VALUE rb_obj_is_thread(VALUE obj);
+VALUE rb_obj_is_mutex(VALUE obj);
+
#if defined(__cplusplus)
#if 0
{ /* satisfy cc-mode */
diff --git a/thread.c b/thread.c
index 1614bfe..34f3ad8 100644
--- a/thread.c
+++ b/thread.c
@@ -3350,6 +3350,17 @@ static const rb_data_type_t mutex_data_type = {
{mutex_mark, mutex_free, mutex_memsize,},
};
+VALUE
+rb_obj_is_mutex(VALUE obj)
+{
+ if (rb_typeddata_is_kind_of(obj, &mutex_data_type)) {
+ return Qtrue;
+ }
+ else {
+ return Qfalse;
+ }
+}
+
static VALUE
mutex_alloc(VALUE klass)
{
diff --git a/vm.c b/vm.c
index bddb4dd..57cb090 100644
--- a/vm.c
+++ b/vm.c
@@ -1780,6 +1780,17 @@ const rb_data_type_t ruby_thread_data_type = {
},
};
+VALUE
+rb_obj_is_thread(VALUE obj)
+{
+ if (rb_typeddata_is_kind_of(obj, &thread_data_type)) {
+ return Qtrue;
+ }
+ else {
+ return Qfalse;
+ }
+}
+
static VALUE
thread_alloc(VALUE klass)
{