Skip to content

Commit

Permalink
Explain why the TPL need to be manuallyDrop on the consumer events ha…
Browse files Browse the repository at this point in the history
…ndler
  • Loading branch information
scanterog committed Nov 7, 2023
1 parent 438af77 commit 0a36b3d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/consumer/base_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ where
let native_tpl = rdsys::rd_kafka_event_topic_partition_list(event.ptr());
TopicPartitionList::from_ptr(native_tpl)
};
// The TPL is owned by the Event and will be destroyed when the event is destroyed.
// Dropping it here will lead to double free.
let mut tpl = ManuallyDrop::new(tpl);
self.context()
.rebalance(self.client.native_client(), err, &mut tpl);
Expand Down Expand Up @@ -185,6 +187,8 @@ where
let tpl = TopicPartitionList::new();
self.context().commit_callback(commit_error, &tpl);
} else {
// The TPL is owned by the Event and will be destroyed when the event is destroyed.
// Dropping it here will lead to double free.
let tpl = ManuallyDrop::new(unsafe { TopicPartitionList::from_ptr(offsets) });
self.context().commit_callback(commit_error, &tpl);
}
Expand Down

0 comments on commit 0a36b3d

Please sign in to comment.