diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java index 64c6508d67d..100e2b85d83 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java @@ -968,12 +968,18 @@ public void scanEntryLog(long entryLogId, EntryLogScanner scanner) throws IOExce // Buffer where to read the entrySize (4 bytes) and the ledgerId (8 bytes) ByteBuf headerBuffer = Unpooled.buffer(4 + 8); BufferedReadChannel bc; + boolean throwExceptionWhenGetChannel = false; // Get the BufferedChannel for the current entry log file try { bc = getChannelForLogId(entryLogId); } catch (IOException e) { LOG.warn("Failed to get channel to scan entry log: " + entryLogId + ".log"); + throwExceptionWhenGetChannel = true; throw e; + } finally { + if (throwExceptionWhenGetChannel) { + headerBuffer.release(); + } } // Start the read position in the current entry log file to be after // the header where all of the ledger entries are. @@ -1027,6 +1033,7 @@ public void scanEntryLog(long entryLogId, EntryLogScanner scanner) throws IOExce pos += entrySize; } } finally { + ReferenceCountUtil.release(headerBuffer); ReferenceCountUtil.release(data); } }