summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 17:28:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 17:28:32 +0000
commita8fb40db8cea8ea998a569989168837e1c33c482 (patch)
tree2730acc4fe71a77aff08be765d5d2b1afb8f77bc
parente78bf7976c0269e8b54165c374fcba7ee68a4d2b (diff)
gc.c: NULL check at memsize
* gc.c (rb_objspace_data_type_memsize): consider NULL data uses no memory without calling dsize function as well as other functions. fix SEGV in test/objspace with RUBY_ISEQ_DUMP_DEBUG=to_binary. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--gc.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/gc.c b/gc.c
index c2b28bb2a8b..3b33eccb934 100644
--- a/gc.c
+++ b/gc.c
@@ -1953,12 +1953,14 @@ rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type
size_t
rb_objspace_data_type_memsize(VALUE obj)
{
- if (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj)->function.dsize) {
- return RTYPEDDATA_TYPE(obj)->function.dsize(RTYPEDDATA_DATA(obj));
- }
- else {
- return 0;
+ if (RTYPEDDATA_P(obj)) {
+ const rb_data_type_t *type = RTYPEDDATA_TYPE(obj);
+ const void *ptr = RTYPEDDATA_DATA(obj);
+ if (ptr && type->function.dsize) {
+ return type->function.dsize(ptr);
+ }
}
+ return 0;
}
const char *