[前][次][番号順一覧][スレッド一覧]

ruby-changes:33229

From: charliesome <ko1@a...>
Date: Tue, 11 Mar 2014 06:55:58 +0900 (JST)
Subject: [ruby-changes:33229] charliesome:r45308 (trunk): ext/objspace: Check fptr before trying to dump FILE object fd

charliesome	2014-03-11 06:55:51 +0900 (Tue, 11 Mar 2014)

  New Revision: 45308

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45308

  Log:
    ext/objspace: Check fptr before trying to dump FILE object fd
    
    Patch by Scott Francis. Closes GH-562.

  Modified files:
    trunk/ChangeLog
    trunk/ext/objspace/objspace_dump.c
    trunk/test/objspace/test_objspace.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45307)
+++ ChangeLog	(revision 45308)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Mar 11 06:54:00 2014  Scott Francis  <scott.francis@s...>
+
+	* 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  <naruse@r...>
 
 	* vm_dump.c (rb_vm_bugreport): show vm maps on FreeBSD.
Index: ext/objspace/objspace_dump.c
===================================================================
--- ext/objspace/objspace_dump.c	(revision 45307)
+++ ext/objspace/objspace_dump.c	(revision 45308)
@@ -230,7 +230,8 @@ dump_object(VALUE obj, struct dump_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L230
 
       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:
Index: test/objspace/test_objspace.rb
===================================================================
--- test/objspace/test_objspace.rb	(revision 45307)
+++ test/objspace/test_objspace.rb	(revision 45308)
@@ -266,4 +266,15 @@ class TestObjSpace < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L266
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]