Skip to content

Commit

Permalink
Merge pull request #1333 from baranowb/UNDERTOW-2072
Browse files Browse the repository at this point in the history
[UNDERTOW-2072] DefaultByteBufferPool.getBuffer() may return null
  • Loading branch information
fl4via authored Oct 11, 2023
2 parents 22ab63b + e38c9e1 commit e92f244
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions core/src/main/java/io/undertow/server/DefaultByteBufferPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public PooledByteBuffer allocate() {
buffer = queue.poll();
if (buffer != null) {
currentQueueLengthUpdater.decrementAndGet(this);
//buffer.clear();
}
}
if (buffer == null) {
Expand Down Expand Up @@ -259,20 +260,23 @@ private static class DefaultPooledBuffer implements PooledByteBuffer {

@Override
public ByteBuffer getBuffer() {
if(referenceCount == 0) {
final ByteBuffer tmp = this.buffer;
//UNDERTOW-2072
if (referenceCount == 0 || tmp == null) {
throw UndertowMessages.MESSAGES.bufferAlreadyFreed();
}
return buffer;
return tmp;
}

@Override
public void close() {
if(referenceCountUpdater.compareAndSet(this, 1, 0)) {
if(leakDetector != null) {
final ByteBuffer tmp = this.buffer;
if (referenceCountUpdater.compareAndSet(this, 1, 0)) {
this.buffer = null;
if (leakDetector != null) {
leakDetector.closed = true;
}
pool.freeInternal(buffer);
this.buffer = null;
pool.freeInternal(tmp);
}
}

Expand Down

0 comments on commit e92f244

Please sign in to comment.