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

ruby-changes:38106

From: nobu <ko1@a...>
Date: Thu, 9 Apr 2015 08:24:51 +0900 (JST)
Subject: [ruby-changes:38106] nobu:r50187 (trunk): raddrinfo.c: fix memory leak

nobu	2015-04-09 08:24:10 +0900 (Thu, 09 Apr 2015)

  New Revision: 50187

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

  Log:
    raddrinfo.c: fix memory leak
    
    * ext/socket/raddrinfo.c (addrinfo_mload): fix memory leak of
      addrinfo.  [ruby-dev:48923] [Bug #11051]

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/raddrinfo.c
    trunk/test/socket/test_addrinfo.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50186)
+++ ChangeLog	(revision 50187)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Apr  9 08:24:03 2015  Masahiro Tomita  <tommy@t...>
+
+	* ext/socket/raddrinfo.c (addrinfo_mload): fix memory leak of
+	  addrinfo.  [ruby-dev:48923] [Bug #11051]
+
 Wed Apr  8 17:45:02 2015  Shannon Skipper  <shannonskipper@g...>
 
 	* version.c (Init_version): the version of the engine or
Index: ext/socket/raddrinfo.c
===================================================================
--- ext/socket/raddrinfo.c	(revision 50186)
+++ ext/socket/raddrinfo.c	(revision 50187)
@@ -1643,6 +1643,7 @@ addrinfo_mload(VALUE self, VALUE ary) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1643
 
         len = res->ai->ai_addrlen;
         memcpy(&ss, res->ai->ai_addr, res->ai->ai_addrlen);
+        rb_freeaddrinfo(res);
         break;
       }
     }
Index: test/socket/test_addrinfo.rb
===================================================================
--- test/socket/test_addrinfo.rb	(revision 50186)
+++ test/socket/test_addrinfo.rb	(revision 50187)
@@ -468,6 +468,17 @@ class TestSocketAddrinfo < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/socket/test_addrinfo.rb#L468
     assert_equal(ai1.canonname, ai2.canonname)
   end
 
+  def test_marshal_memory_leak
+    bug11051 = '[ruby-dev:48923] [Bug #11051]'
+    assert_no_memory_leak(%w[-rsocket], <<-prep, <<-code, bug11051, rss: true, limit: 1.1)
+    d = Marshal.dump(Addrinfo.tcp("127.0.0.1", 80))
+    1000.times {Marshal.load(d)}
+    prep
+    GC.start
+    20_000.times {Marshal.load(d)}
+    code
+  end
+
   if Socket.const_defined?("AF_INET6") && Socket::AF_INET6.is_a?(Integer)
 
     def test_addrinfo_new_inet6

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

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