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

shoothzj pushed a commit to branch branch-4.17
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/branch-4.17 by this push:
     new 173def8b3a fix: resource leak when JournalChannel is not fully 
initialized (#4340)
173def8b3a is described below

commit 173def8b3a8f5afc7c2519a95352be271be9f442
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();
         }
     }
 

Reply via email to