ruby-changes:33739
From: nagachika <ko1@a...>
Date: Mon, 5 May 2014 02:32:53 +0900 (JST)
Subject: [ruby-changes:33739] nagachika:r45820 (ruby_2_1): merge revision(s) r45291, r45299, r45314, r45325: [Backport #9518]
nagachika 2014-05-05 02:32:44 +0900 (Mon, 05 May 2014) New Revision: 45820 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45820 Log: merge revision(s) r45291,r45299,r45314,r45325: [Backport #9518] * ext/dl/cptr.c (dlptr_free), ext/dl/handle.c (dlhandle_free), ext/fiddle/handle.c (fiddle_handle_free), ext/fiddle/pointer.c (fiddle_ptr_free): fix memory leak. based on the patch Heesob Park at [ruby-dev:48021] [Bug #9599]. Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/ext/dl/cptr.c branches/ruby_2_1/ext/dl/handle.c branches/ruby_2_1/ext/fiddle/handle.c branches/ruby_2_1/ext/fiddle/pointer.c branches/ruby_2_1/test/dl/test_cptr.rb branches/ruby_2_1/test/dl/test_handle.rb branches/ruby_2_1/test/fiddle/test_handle.rb branches/ruby_2_1/test/fiddle/test_pointer.rb branches/ruby_2_1/test/ruby/envutil.rb branches/ruby_2_1/version.h Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 45819) +++ ruby_2_1/ChangeLog (revision 45820) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Mon May 5 02:21:48 2014 Nobuyoshi Nakada <nobu@r...> + + * ext/dl/cptr.c (dlptr_free), ext/dl/handle.c (dlhandle_free), + ext/fiddle/handle.c (fiddle_handle_free), + ext/fiddle/pointer.c (fiddle_ptr_free): fix memory leak. + based on the patch Heesob Park at [ruby-dev:48021] [Bug #9599]. + Mon May 5 01:20:27 2014 Eric Wong <e@8...> * gc.c (rb_gc_writebarrier): drop special case for big hash/array Index: ruby_2_1/ext/dl/cptr.c =================================================================== --- ruby_2_1/ext/dl/cptr.c (revision 45819) +++ ruby_2_1/ext/dl/cptr.c (revision 45820) @@ -49,6 +49,7 @@ dlptr_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/dl/cptr.c#L49 (*(data->free))(data->ptr); } } + xfree(ptr); } static size_t Index: ruby_2_1/ext/dl/handle.c =================================================================== --- ruby_2_1/ext/dl/handle.c (revision 45819) +++ ruby_2_1/ext/dl/handle.c (revision 45820) @@ -38,6 +38,7 @@ dlhandle_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/dl/handle.c#L38 if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){ dlclose(dlhandle->ptr); } + xfree(ptr); } static size_t Index: ruby_2_1/ext/fiddle/pointer.c =================================================================== --- ruby_2_1/ext/fiddle/pointer.c (revision 45819) +++ ruby_2_1/ext/fiddle/pointer.c (revision 45820) @@ -56,6 +56,7 @@ fiddle_ptr_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/fiddle/pointer.c#L56 (*(data->free))(data->ptr); } } + xfree(ptr); } static size_t Index: ruby_2_1/ext/fiddle/handle.c =================================================================== --- ruby_2_1/ext/fiddle/handle.c (revision 45819) +++ ruby_2_1/ext/fiddle/handle.c (revision 45820) @@ -40,6 +40,7 @@ fiddle_handle_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/fiddle/handle.c#L40 if( fiddle_handle->ptr && fiddle_handle->open && fiddle_handle->enable_close ){ dlclose(fiddle_handle->ptr); } + xfree(ptr); } static size_t Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 45819) +++ ruby_2_1/version.h (revision 45820) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-05-05" -#define RUBY_PATCHLEVEL 90 +#define RUBY_PATCHLEVEL 91 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 5 Index: ruby_2_1/test/ruby/envutil.rb =================================================================== --- ruby_2_1/test/ruby/envutil.rb (revision 45819) +++ ruby_2_1/test/ruby/envutil.rb (revision 45820) @@ -372,7 +372,7 @@ eom https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/envutil.rb#L372 assert_warning(*args) {$VERBOSE = false; yield} end - def assert_no_memory_leak(args, prepare, code, message=nil, limit: 1.5, **opt) + def assert_no_memory_leak(args, prepare, code, message=nil, limit: 1.5, rss: false, **opt) require_relative 'memory_status' token = "\e[7;1m#{$$.to_s}:#{Time.now.strftime('%s.%L')}:#{rand(0x10000).to_s(16)}:\e[m" token_dump = token.dump @@ -397,7 +397,7 @@ eom https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/envutil.rb#L397 before = err.sub!(/^#{token_re}START=(\{.*\})\n/, '') && Memory::Status.parse($1) after = err.sub!(/^#{token_re}FINAL=(\{.*\})\n/, '') && Memory::Status.parse($1) assert_equal([true, ""], [status.success?, err], message) - ([:size, :rss] & after.members).each do |n| + ([:size, (rss && :rss)] & after.members).each do |n| b = before[n] a = after[n] next unless a > 0 and b > 0 Index: ruby_2_1/test/fiddle/test_pointer.rb =================================================================== --- ruby_2_1/test/fiddle/test_pointer.rb (revision 45819) +++ ruby_2_1/test/fiddle/test_pointer.rb (revision 45820) @@ -230,5 +230,9 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/fiddle/test_pointer.rb#L230 assert_raise(DLError) {nullpo[0]} assert_raise(DLError) {nullpo[0] = 1} end + + def test_no_memory_leak + assert_no_memory_leak(%w[-W0 -rfiddle.so], '', '100_000.times {Fiddle::Pointer.allocate}', rss: true) + end end end if defined?(Fiddle) Index: ruby_2_1/test/fiddle/test_handle.rb =================================================================== --- ruby_2_1/test/fiddle/test_handle.rb (revision 45819) +++ ruby_2_1/test/fiddle/test_handle.rb (revision 45820) @@ -1,5 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/fiddle/test_handle.rb#L1 begin require_relative 'helper' + require_relative '../ruby/envutil' rescue LoadError end @@ -7,6 +8,8 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/fiddle/test_handle.rb#L8 class TestHandle < TestCase include Fiddle + include Test::Unit::Assertions + def test_to_i handle = Fiddle::Handle.new(LIBC_SO) assert_kind_of Integer, handle.to_i @@ -185,5 +188,9 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/fiddle/test_handle.rb#L188 Socket.gethostbyname("localhost") Fiddle.dlopen("/lib/libc.so.7").sym('strcpy') end if /freebsd/=~ RUBY_PLATFORM + + def test_no_memory_leak + assert_no_memory_leak(%w[-W0 -rfiddle.so], '', '100_000.times {Fiddle::Handle.allocate}; GC.start', rss: true) + end end end if defined?(Fiddle) Index: ruby_2_1/test/dl/test_cptr.rb =================================================================== --- ruby_2_1/test/dl/test_cptr.rb (revision 45819) +++ ruby_2_1/test/dl/test_cptr.rb (revision 45820) @@ -219,4 +219,8 @@ module DL https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/dl/test_cptr.rb#L219 assert_raise(DLError) {nullpo[0] = 1} end end + + def test_no_memory_leak + assert_no_memory_leak(%w[-W0 -rdl.so], '', '100_000.times {DL::CPtr.allocate}', rss: true) + end end Index: ruby_2_1/test/dl/test_handle.rb =================================================================== --- ruby_2_1/test/dl/test_handle.rb (revision 45819) +++ ruby_2_1/test/dl/test_handle.rb (revision 45820) @@ -184,4 +184,8 @@ module DL https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/dl/test_handle.rb#L184 DL.dlopen("/lib/libc.so.7").sym('strcpy') end if /freebsd/=~ RUBY_PLATFORM end + + def test_no_memory_leak + assert_no_memory_leak(%w[-W0 -rdl.so], '', '100_000.times {DL::Handle.allocate}; GC.start', rss: true) + end end Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r45291,45299,45314,45325 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/