This is an automated email from the ASF dual-hosted git repository.
shoothzj pushed a commit to branch branch-4.16
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/branch-4.16 by this push:
new e424a1aa76 fix: resource leak when JournalChannel is not fully
initialized (#4340)
e424a1aa76 is described below
commit e424a1aa76e17828b561de7bb36dd5037e08dd83
Author: ZhangJian He <[email protected]>
AuthorDate: Thu May 9 18:00:25 2024 +0800
fix: resource leak when JournalChannel is not fully initialized (#4340)
(cherry picked from commit 82a7dd3064bafbdc5be5fedd2bb99b77b814f5cd)
---
.../src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java
index 5c5a02252d..b3759b6878 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java
@@ -192,7 +192,7 @@ class JournalChannel implements Closeable {
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);
@@ -299,6 +299,8 @@ class JournalChannel implements Closeable {
public void close() throws IOException {
if (bc != null) {
bc.close();
+ } else if (fc != null) {
+ fc.close();
}
}