This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 82a7dd3064 fix: resource leak when JournalChannel is not fully 
initialized (#4340)
82a7dd3064 is described below

commit 82a7dd3064bafbdc5be5fedd2bb99b77b814f5cd
Author: ZhangJian He <[email protected]>
AuthorDate: Thu May 9 18:00:25 2024 +0800

    fix: resource leak when JournalChannel is not fully initialized (#4340)
---
 .../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();
         }
     }
 

Reply via email to