Skip to content

Commit

Permalink
fix: resource leak when JournalChannel is not fully initialized (#4340)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoothzj authored May 9, 2024
1 parent f030b65 commit 82a7dd3
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private JournalChannel(File journalDirectory, long logId,
writeHeader(bcBuilder, writeBufferSize);
} else { // open an existing file to read.
fc = channel.getFileChannel();
bc = null; // readonly
// readonly, use fileChannel directly, no need to use BufferedChannel

ByteBuffer bb = ByteBuffer.allocate(VERSION_HEADER_SIZE);
int c = fc.read(bb);
Expand Down Expand Up @@ -299,6 +299,8 @@ int read(ByteBuffer dst)
public void close() throws IOException {
if (bc != null) {
bc.close();
} else if (fc != null) {
fc.close();
}
}

Expand Down

0 comments on commit 82a7dd3

Please sign in to comment.