Skip to content

Fix the destruction order of handle & destroy_flags #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

filimonov
Copy link
Contributor

@filimonov filimonov commented Mar 11, 2025

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.

…ndleBase

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.
@filimonov
Copy link
Contributor Author

example report from the memory sanitizer:

==28==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x5555952c97dc in cppkafka::KafkaHandleBase::HandleDeleter::operator()(rd_kafka_s*) build_docker/./build_docker/./contrib/cppkafka/src/kafka_handle_base.cpp:303:5
    #1 0x5555952c51dc in std::__1::unique_ptr<rd_kafka_s, cppkafka::KafkaHandleBase::HandleDeleter>::reset[abi:ne190107](rd_kafka_s*) build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:292:7
    #2 0x5555952c51dc in std::__1::unique_ptr<rd_kafka_s, cppkafka::KafkaHandleBase::HandleDeleter>::~unique_ptr[abi:ne190107]() build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:261:71
    #3 0x5555952c51dc in cppkafka::KafkaHandleBase::~KafkaHandleBase() build_docker/./contrib/cppkafka/include/cppkafka/kafka_handle_base.h:66:40
    #4 0x5555952bebac in cppkafka::Consumer::~Consumer() build_docker/./build_docker/./contrib/cppkafka/src/consumer.cpp:99:1

  Member fields were destroyed
    #0 0x55555dec328d in __sanitizer_dtor_callback_fields (/usr/bin/clickhouse+0x896f28d) (BuildId: f0dd81bc4480871c462431322414a317857334c2)
    #1 0x5555952c5182 in cppkafka::KafkaHandleBase::~KafkaHandleBase() build_docker/./contrib/cppkafka/include/cppkafka/kafka_handle_base.h:395:9
    #2 0x5555952c5182 in cppkafka::KafkaHandleBase::~KafkaHandleBase() build_docker/./contrib/cppkafka/include/cppkafka/kafka_handle_base.h:66:40
    #3 0x5555952bebac in cppkafka::Consumer::~Consumer() build_docker/./build_docker/./contrib/cppkafka/src/consumer.cpp:99:1

SUMMARY: MemorySanitizer: use-of-uninitialized-value build_docker/./build_docker/./contrib/cppkafka/src/kafka_handle_base.cpp:303:5 in cppkafka::KafkaHandleBase::HandleDeleter::operator()(rd_kafka_s*)
Exiting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant