From f5299e93a7914e8ba588031a0603014c73a6c3fa Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 10 May 2015 12:32:47 +0000 Subject: [PATCH] gc.c: never call dmark for NULL * gc.c (gc_mark_children): call dmark function for non-NULL pointers only, so that DATA_PTR can be NULL safely now. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ gc.c | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ae7f9e826..4560a6839c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun May 10 21:32:45 2015 Nobuyoshi Nakada + + * gc.c (gc_mark_children): call dmark function for non-NULL + pointers only, so that DATA_PTR can be NULL safely now. + Sun May 10 16:23:58 2015 Kazuki Tsujimoto * proc.c (proc_binding): fix segmentation fault on marking phase. diff --git a/gc.c b/gc.c index 46551f4558..3b2d5c9519 100644 --- a/gc.c +++ b/gc.c @@ -4300,12 +4300,14 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj) break; case T_DATA: - if (RTYPEDDATA_P(obj)) { - RUBY_DATA_FUNC mark_func = any->as.typeddata.type->function.dmark; - if (mark_func) (*mark_func)(DATA_PTR(obj)); - } - else { - if (any->as.data.dmark) (*any->as.data.dmark)(DATA_PTR(obj)); + { + void *const ptr = DATA_PTR(obj); + if (ptr) { + RUBY_DATA_FUNC mark_func = RTYPEDDATA_P(obj) ? + any->as.typeddata.type->function.dmark : + any->as.data.dmark; + if (mark_func) (*mark_func)(ptr); + } } break;