Skip to content

Commit decf797

Browse files
mtopolnikclaude
andcommitted
Fix buffer0 leak in QwpWebSocketSender constructor
If the second MicrobatchBuffer allocation (buffer1) throws, the already-allocated buffer0 leaks its native memory. Neither connect() nor createForTesting() catch constructor failures, so the cleanup must happen in the constructor itself. Wrap the buffer1 allocation in a try-catch that closes buffer0 before re-throwing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 65270d6 commit decf797

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

core/src/main/java/io/questdb/client/cutlass/qwp/client/QwpWebSocketSender.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ private QwpWebSocketSender(
183183
if (inFlightWindowSize > 1) {
184184
int microbatchBufferSize = Math.max(DEFAULT_MICROBATCH_BUFFER_SIZE, autoFlushBytes * 2);
185185
this.buffer0 = new MicrobatchBuffer(microbatchBufferSize, autoFlushRows, autoFlushBytes, autoFlushIntervalNanos);
186-
this.buffer1 = new MicrobatchBuffer(microbatchBufferSize, autoFlushRows, autoFlushBytes, autoFlushIntervalNanos);
186+
try {
187+
this.buffer1 = new MicrobatchBuffer(microbatchBufferSize, autoFlushRows, autoFlushBytes, autoFlushIntervalNanos);
188+
} catch (Throwable t) {
189+
buffer0.close();
190+
throw t;
191+
}
187192
this.activeBuffer = buffer0;
188193
}
189194
}

0 commit comments

Comments
 (0)