From c8c539a19813a0ff44e05f9639a56d686876d4e1 Mon Sep 17 00:00:00 2001 From: charliesome Date: Mon, 10 Mar 2014 21:55:51 +0000 Subject: ext/objspace: Check fptr before trying to dump FILE object fd Patch by Scott Francis. Closes GH-562. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ ext/objspace/objspace_dump.c | 3 ++- test/objspace/test_objspace.rb | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5648d20d33..c6108ab4d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Mar 11 06:54:00 2014 Scott Francis + + * ext/objspace/objspace_dump.c: Check fptr before trying to dump RFILE + object fd. [GH-562] + + * test/objspace/test_objspace.rb: add test + Tue Mar 11 02:04:36 2014 NARUSE, Yui * vm_dump.c (rb_vm_bugreport): show vm maps on FreeBSD. diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index 6b3bf44489..076d4fbaa1 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -230,7 +230,8 @@ dump_object(VALUE obj, struct dump_config *dc) case T_FILE: fptr = RFILE(obj)->fptr; - dump_append(dc, ", \"fd\":%d", fptr->fd); + if (fptr) + dump_append(dc, ", \"fd\":%d", fptr->fd); break; case T_ZOMBIE: diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 42dc55de9f..ea89a87e18 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -266,4 +266,15 @@ class TestObjSpace < Test::Unit::TestCase File.unlink(output) end end + + def test_dump_uninitialized_file + assert_in_out_err(%[-robjspace], <<-RUBY) do |output, error| + puts ObjectSpace.dump(File.allocate) + RUBY + assert_equal [], error + json = JSON.load(output.join) + assert_equal "FILE", json["type"] + assert_nil json["fd"] + end + end end -- cgit v1.2.3