Skip to content

Commit c40b89e

Browse files
lhotarisrinath-ctds
authored andcommitted
[fix][broker] Fix ByteBuf memory leak in REST API for publishing messages (apache#24228)
(cherry picked from commit 0c8e88c) (cherry picked from commit abb3c84)
1 parent f30c4e2 commit c40b89e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/broker/rest/TopicsBase.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.apache.pulsar.broker.lookup.LookupResult;
6464
import org.apache.pulsar.broker.namespace.LookupOptions;
6565
import org.apache.pulsar.broker.service.BrokerServiceException;
66+
import org.apache.pulsar.broker.service.Topic;
6667
import org.apache.pulsar.broker.service.schema.SchemaRegistry;
6768
import org.apache.pulsar.broker.service.schema.exceptions.SchemaException;
6869
import org.apache.pulsar.broker.web.RestException;
@@ -282,8 +283,14 @@ private CompletableFuture<Position> publishSingleMessageToPartition(String topic
282283
.remove(topicName.getPartitionIndex());
283284
} else {
284285
try {
285-
t.get().publishMessage(messageToByteBuf(message),
286-
RestMessagePublishContext.get(publishResult, t.get(), System.nanoTime()));
286+
ByteBuf headersAndPayload = messageToByteBuf(message);
287+
try {
288+
Topic topicObj = t.get();
289+
topicObj.publishMessage(headersAndPayload,
290+
RestMessagePublishContext.get(publishResult, topicObj, System.nanoTime()));
291+
} finally {
292+
headersAndPayload.release();
293+
}
287294
} catch (Exception e) {
288295
if (log.isDebugEnabled()) {
289296
log.debug("Fail to publish single messages to topic {}: {} ",

0 commit comments

Comments
 (0)