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

chenhang 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 cc1c2e012f Issue 4134: Fixing memory leak error when using 
DirectEntryLogger (#4135)
cc1c2e012f is described below

commit cc1c2e012f052d63f585be41c74beecbef71334d
Author: grayson <[email protected]>
AuthorDate: Mon Jan 8 11:59:10 2024 +0800

    Issue 4134: Fixing memory leak error when using DirectEntryLogger (#4135)
    
    ### Motivation
    
    When we use DirectIO and a catch up read occurs, a memory leak occurs 
because the ByteBuf is not released.
    
    Because although in the `internalReadEntry` method in `DirectEntryLogger`, 
even if the upper layer `fillReadAheadCache` uses the 
`ReferenceCountUtil.release(entry)` method in the finally block to release 
ByteBuf, it will still cause an exception thrown by `internalReadEntry`, and 
the `entryLogger.readEntry` method happens to be in try. ..catch unexpected, 
causing ByteBuf to not be released correctly
    
    ### Changes
    
    Master Issue: #4134
---
 .../bookkeeper/bookie/storage/directentrylogger/DirectEntryLogger.java   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectEntryLogger.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectEntryLogger.java
index 323727217d..e18364e61d 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectEntryLogger.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectEntryLogger.java
@@ -252,6 +252,7 @@ public class DirectEntryLogger implements EntryLogger {
                 long thisEntryId = buf.getLong(8);
                 if (thisLedgerId != ledgerId
                     || thisEntryId != entryId) {
+                    ReferenceCountUtil.release(buf);
                     throw new IOException(
                             exMsg("Bad location").kv("location", location)
                             .kv("expectedLedger", 
ledgerId).kv("expectedEntry", entryId)

Reply via email to