From 3ff96dc35a1b4700ffc2151c9fd700eb2b289470 Mon Sep 17 00:00:00 2001 From: Yuval Lifshitz Date: Tue, 20 Jun 2023 10:21:33 +0000 Subject: [PATCH] rgw/kafka: fix potential memory leak when push to queue fails Signed-off-by: Yuval Lifshitz --- src/rgw/rgw_kafka.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_kafka.cc b/src/rgw/rgw_kafka.cc index 678e6d62bfe..832c4667b94 100644 --- a/src/rgw/rgw_kafka.cc +++ b/src/rgw/rgw_kafka.cc @@ -602,7 +602,9 @@ public: if (stopped) { return STATUS_MANAGER_STOPPED; } - if (messages.push(new message_wrapper_t(conn_name, topic, message, nullptr))) { + auto message_wrapper = std::make_unique(conn_name, topic, message, nullptr); + if (messages.push(message_wrapper.get())) { + std::ignore = message_wrapper.release(); ++queued; return STATUS_OK; } @@ -616,7 +618,9 @@ public: if (stopped) { return STATUS_MANAGER_STOPPED; } - if (messages.push(new message_wrapper_t(conn_name, topic, message, cb))) { + auto message_wrapper = std::make_unique(conn_name, topic, message, cb); + if (messages.push(message_wrapper.get())) { + std::ignore = message_wrapper.release(); ++queued; return STATUS_OK; } -- 2.39.5