Skip to content

Commit cdb9d15

Browse files
authored
Merge pull request #19 from casperisfine/fix-read-adapter-leak
Undo BufferedIO#rbuf_consume_all_shareable! optimization
2 parents 735c047 + 7efa16d commit cdb9d15

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

lib/net/protocol.rb

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def read(len, dest = ''.b, ignore_eof = false)
157157
read_bytes = 0
158158
begin
159159
while read_bytes + rbuf_size < len
160-
if s = rbuf_consume_all_shareable!
160+
if s = rbuf_consume_all
161161
read_bytes += s.bytesize
162162
dest << s
163163
end
@@ -178,7 +178,7 @@ def read_all(dest = ''.b)
178178
read_bytes = 0
179179
begin
180180
while true
181-
if s = rbuf_consume_all_shareable!
181+
if s = rbuf_consume_all
182182
read_bytes += s.bytesize
183183
dest << s
184184
end
@@ -250,18 +250,8 @@ def rbuf_size
250250
@rbuf.bytesize - @rbuf_offset
251251
end
252252

253-
# Warning: this method may share the buffer to avoid
254-
# copying. The caller must no longer use the returned
255-
# string once rbuf_fill has been called again
256-
def rbuf_consume_all_shareable!
257-
@rbuf_empty = true
258-
buf = if @rbuf_offset == 0
259-
@rbuf
260-
else
261-
@rbuf.byteslice(@rbuf_offset..-1)
262-
end
263-
@rbuf_offset = @rbuf.bytesize
264-
buf
253+
def rbuf_consume_all
254+
rbuf_consume if rbuf_size > 0
265255
end
266256

267257
def rbuf_consume(len = nil)

0 commit comments

Comments
 (0)