Skip to content

Commit

Permalink
Squash memory leak when calling flush with an empty buffer
Browse files Browse the repository at this point in the history
[#1552 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
fcheung authored and jeremy committed Dec 10, 2008
1 parent 8fcd9cf commit 8da5c55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion activesupport/lib/active_support/buffered_logger.rb
Expand Up @@ -94,9 +94,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

Expand Down
6 changes: 6 additions & 0 deletions activesupport/test/buffered_logger_test.rb
Expand Up @@ -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

0 comments on commit 8da5c55

Please sign in to comment.