[Broker] Fix direct memory leak in getLastMessageId
@@ -2586,13 +2586,18 @@ public class PersistentTopic extends AbstractTopic
ledgerImpl.asyncReadEntry(position, new AsyncCallbacks.ReadEntryCallback() {
@Override
public void readEntryComplete(Entry entry, Object ctx) {
+ try {
MessageMetadata metadata = Commands.parseMessageMetadata(entry.getDataBuffer());
if (metadata.hasNumMessagesInBatch()) {
completableFuture.complete(new BatchMessageIdImpl(position.getLedgerId(), position.getEntryId(),
partitionIndex, metadata.getNumMessagesInBatch() - 1));
} else {
completableFuture
- .complete(new MessageIdImpl(position.getLedgerId(), position.getEntryId(), partitionIndex));
+ .complete(new MessageIdImpl(position.getLedgerId(), position.getEntryId(),
+ partitionIndex));
+ }
+ } finally {
+ entry.release();
}
}
