Skip to content

Commit 9424527

Browse files
lhotarimanas-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 72eb29f)
1 parent 3518ee8 commit 9424527

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
@@ -61,6 +61,7 @@
6161
import org.apache.pulsar.broker.lookup.LookupResult;
6262
import org.apache.pulsar.broker.namespace.LookupOptions;
6363
import org.apache.pulsar.broker.service.BrokerServiceException;
64+
import org.apache.pulsar.broker.service.Topic;
6465
import org.apache.pulsar.broker.service.schema.SchemaRegistry;
6566
import org.apache.pulsar.broker.service.schema.exceptions.SchemaException;
6667
import org.apache.pulsar.broker.web.RestException;
@@ -280,8 +281,14 @@ private CompletableFuture<PositionImpl> publishSingleMessageToPartition(String t
280281
.remove(topicName.getPartitionIndex());
281282
} else {
282283
try {
283-
t.get().publishMessage(messageToByteBuf(message),
284-
RestMessagePublishContext.get(publishResult, t.get(), System.nanoTime()));
284+
ByteBuf headersAndPayload = messageToByteBuf(message);
285+
try {
286+
Topic topicObj = t.get();
287+
topicObj.publishMessage(headersAndPayload,
288+
RestMessagePublishContext.get(publishResult, topicObj, System.nanoTime()));
289+
} finally {
290+
headersAndPayload.release();
291+
}
285292
} catch (Exception e) {
286293
if (log.isDebugEnabled()) {
287294
log.debug("Fail to publish single messages to topic {}: {} ",

0 commit comments

Comments
 (0)