fix memory leak
### Motivation
This pr fix memory leak by release bytebuf.
@@ -81,10 +81,11 @@ public class ManagedLedgerInterceptorImpl implements ManagedLedgerInterceptor {
@Override
public void onManagedLedgerLastLedgerInitialize(String name, LedgerHandle lh) {
+ LedgerEntries ledgerEntries = null;
try {
for (BrokerEntryMetadataInterceptor interceptor : brokerEntryMetadataInterceptors) {
if (interceptor instanceof AppendIndexMetadataInterceptor && lh.getLastAddConfirmed() >= 0) {
- LedgerEntries ledgerEntries =
+ ledgerEntries =
lh.read(lh.getLastAddConfirmed(), lh.getLastAddConfirmed());
for (LedgerEntry entry : ledgerEntries) {
BrokerEntryMetadata brokerEntryMetadata =
@@ -99,6 +100,10 @@ public class ManagedLedgerInterceptorImpl implements ManagedLedgerInterceptor {
}
} catch (org.apache.bookkeeper.client.api.BKException | InterruptedException e) {
log.error("[{}] Read last entry error.", name, e);
+ } finally {
+ if (ledgerEntries != null) {
+ ledgerEntries.close();
+ }
}
}
