summaryrefslogtreecommitdiff
path: root/ext/-test-
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-19 14:36:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-19 14:36:17 +0000
commit263a0f7f161f3dbf46a2af1d440fa570a66bb5bf (patch)
tree99b4e29261e713ca83ac5eafa8cdb0b49342f31c /ext/-test-
parent0a907a3792e3ce8d25ffb0ff68428c64160f5e6d (diff)
test for [Bug #12670]
heap corruption by deferred free. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-')
-rw-r--r--ext/-test-/typeddata/typeddata.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/-test-/typeddata/typeddata.c b/ext/-test-/typeddata/typeddata.c
index 1c5d677..ae06096 100644
--- a/ext/-test-/typeddata/typeddata.c
+++ b/ext/-test-/typeddata/typeddata.c
@@ -2,19 +2,43 @@
static const rb_data_type_t test_data = {
"typed_data",
+ {NULL, ruby_xfree, NULL},
+ NULL, NULL,
+ 0/* deferred free */,
};
static VALUE
+test_alloc(VALUE klass)
+{
+ char *p;
+ return TypedData_Make_Struct(klass, char, &test_data, p);
+}
+
+static VALUE
test_check(VALUE self, VALUE obj)
{
rb_check_typeddata(obj, &test_data);
return obj;
}
+static VALUE
+test_make(VALUE klass, VALUE num)
+{
+ unsigned long i, n = NUM2UINT(num);
+
+ for (i = 0; i < n; i++) {
+ test_alloc(klass);
+ }
+
+ return Qnil;
+}
+
void
Init_typeddata(void)
{
VALUE mBug = rb_define_module("Bug");
VALUE klass = rb_define_class_under(mBug, "TypedData", rb_cData);
+ rb_define_alloc_func(klass, test_alloc);
rb_define_singleton_method(klass, "check", test_check, 1);
+ rb_define_singleton_method(klass, "make", test_make, 1);
}