Skip to content

Commit f56b2fe

Browse files
committed
Fix MemorySanitizer Warning by Reordering Member Variables in KafkaHandleBase
The MemorySanitizer detected a use-of-uninitialized-value issue caused by the destruction order in KafkaHandleBase. Specifically, the deleter of the Kafka handle accessed destroy_flags_ after it had been destroyed because destroy_flags_ was declared after handle_. This commit reorders the member declarations so that destroy_flags_ is declared before handle_. The constructor's initializer list is also updated accordingly to match the new declaration order.
1 parent 9c5ea0e commit f56b2fe

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

include/cppkafka/kafka_handle_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ class CPPKAFKA_API KafkaHandleBase {
391391
Configuration config_;
392392
TopicConfigurationMap topic_configurations_;
393393
std::mutex topic_configurations_mutex_;
394-
HandlePtr handle_;
395394
int destroy_flags_;
395+
HandlePtr handle_;
396396
};
397397

398398
} // cppkafka

src/kafka_handle_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace cppkafka {
4848
const milliseconds KafkaHandleBase::DEFAULT_TIMEOUT{1000};
4949

5050
KafkaHandleBase::KafkaHandleBase(Configuration config)
51-
: timeout_ms_(DEFAULT_TIMEOUT), config_(move(config)), handle_(nullptr, HandleDeleter(this)), destroy_flags_(0) {
51+
: timeout_ms_(DEFAULT_TIMEOUT), config_(move(config)), destroy_flags_(0), handle_(nullptr, HandleDeleter(this)) {
5252
auto& maybe_config = config_.get_default_topic_configuration();
5353
if (maybe_config) {
5454
maybe_config->set_as_opaque();

0 commit comments

Comments
 (0)