Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 fcheung authored jeremy committed
5 activesupport/lib/active_support/buffered_logger.rb
View
@@ -96,9 +96,12 @@ def flush
@guard.synchronize do
unless buffer.empty?
old_buffer = buffer
- clear_buffer
@log.write(old_buffer.join)
end
+
+ # Important to do this even if buffer was empty or else @buffer will
+ # accumulate empty arrays for each request where nothing was logged.
+ clear_buffer
end
end
6 activesupport/test/buffered_logger_test.rb
View
@@ -137,4 +137,10 @@ def test_logger_should_maintain_separate_buffers_for_each_thread
assert @output.string.include?("a\nb\nc\n")
assert @output.string.include?("x\ny\nz\n")
end
+
+ def test_flush_should_remove_empty_buffers
+ @logger.send :buffer
+ @logger.expects :clear_buffer
+ @logger.flush
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.