Skip to content

Commit

Permalink
Issue #5499 - takeBuffer releases all the buffers in the list
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Nov 12, 2020
1 parent d75e6de commit e0031e0
Showing 1 changed file with 11 additions and 6 deletions.
Expand Up @@ -79,23 +79,28 @@ public void copyBuffer(ByteBuffer buffer)

public ByteBuffer takeByteBuffer()
{
ByteBuffer combinedBuffer;
if (_buffers.size() == 1)
{
combinedBuffer = _buffers.get(0);
_buffers.clear();
return combinedBuffer;
}

int length = getLength();
ByteBuffer combinedBuffer = _bufferPool.acquire(length, false);
combinedBuffer = _bufferPool.acquire(length, false);
for (ByteBuffer buffer : _buffers)
{
combinedBuffer.put(buffer);
_bufferPool.release(buffer);
}
_buffers.clear();
return combinedBuffer;
}

public ByteBuffer toByteBuffer()
{
if (_buffers.size() == 1)
return _buffers.get(0);

ByteBuffer combinedBuffer = takeByteBuffer();
_buffers.forEach(_bufferPool::release);
_buffers.clear();
_buffers.add(combinedBuffer);
return combinedBuffer;
}
Expand Down

0 comments on commit e0031e0

Please sign in to comment.