Skip to content

Commit 9c3d9fa

Browse files
committed
Ensure that the ByteBufferBsonOutput releases all on close
JAVA-2460
1 parent 1725c44 commit 9c3d9fa

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

driver-core/src/main/com/mongodb/connection/ByteBufBsonDocument.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ static ByteBufBsonDocument createOne(final ByteBufferBsonOutput bsonOutput, fina
7575
}
7676

7777
static List<ByteBufBsonDocument> create(final ByteBufferBsonOutput bsonOutput, final int startPosition) {
78-
CompositeByteBuf outputByteBuf = new CompositeByteBuf(bsonOutput.getByteBuffers());
78+
List<ByteBuf> duplicateByteBuffers = bsonOutput.getByteBuffers();
79+
CompositeByteBuf outputByteBuf = new CompositeByteBuf(duplicateByteBuffers);
7980
outputByteBuf.position(startPosition);
8081
List<ByteBufBsonDocument> documents = new ArrayList<ByteBufBsonDocument>();
8182
int curDocumentStartPosition = startPosition;
@@ -88,7 +89,9 @@ static List<ByteBufBsonDocument> create(final ByteBufferBsonOutput bsonOutput, f
8889
curDocumentStartPosition += documentSizeInBytes;
8990
outputByteBuf.position(outputByteBuf.position() + documentSizeInBytes - 4);
9091
}
91-
92+
for (ByteBuf byteBuffer : duplicateByteBuffers) {
93+
byteBuffer.release();
94+
}
9295
return documents;
9396
}
9497

driver-core/src/main/com/mongodb/connection/CompositeByteBuf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CompositeByteBuf implements ByteBuf {
4141

4242
int offset = 0;
4343
for (ByteBuf cur : buffers) {
44-
Component component = new Component(cur.duplicate().order(ByteOrder.LITTLE_ENDIAN), offset);
44+
Component component = new Component(cur.asReadOnly().order(ByteOrder.LITTLE_ENDIAN), offset);
4545
components.add(component);
4646
offset = component.endOffset;
4747
}

0 commit comments

Comments
 (0)