Skip to content
This repository
Browse code

Squash memory leak when calling flush with an empty buffer

[#1552 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 9f69ff12d44c4d1e475fd6efede120ccedba3b3e 1 parent d45e2c7
Frederick Cheung authored December 10, 2008 jeremy committed December 10, 2008
5  activesupport/lib/active_support/buffered_logger.rb
@@ -96,9 +96,12 @@ def flush
96 96
       @guard.synchronize do
97 97
         unless buffer.empty?
98 98
           old_buffer = buffer
99  
-          clear_buffer
100 99
           @log.write(old_buffer.join)
101 100
         end
  101
+
  102
+        # Important to do this even if buffer was empty or else @buffer will
  103
+        # accumulate empty arrays for each request where nothing was logged.
  104
+        clear_buffer
102 105
       end
103 106
     end
104 107
 
6  activesupport/test/buffered_logger_test.rb
@@ -137,4 +137,10 @@ def test_logger_should_maintain_separate_buffers_for_each_thread
137 137
     assert @output.string.include?("a\nb\nc\n")
138 138
     assert @output.string.include?("x\ny\nz\n")
139 139
   end
  140
+
  141
+  def test_flush_should_remove_empty_buffers
  142
+    @logger.send :buffer
  143
+    @logger.expects :clear_buffer
  144
+    @logger.flush
  145
+  end
140 146
 end

0 notes on commit 9f69ff1

Please sign in to comment.
Something went wrong with that request. Please try again.