You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/09/04 16:07:27 UTC

[GitHub] [pulsar] BewareMyPower commented on a diff in pull request #17395: [fix][cpp] Fix potential segfault when resending messages

BewareMyPower commented on code in PR #17395:
URL: https://github.com/apache/pulsar/pull/17395#discussion_r962337056


##########
pulsar-client-cpp/lib/PeriodicTask.cc:
##########
@@ -27,9 +27,14 @@ void PeriodicTask::start() {
     }
     state_ = Ready;
     if (periodMs_ >= 0) {
-        auto self = shared_from_this();
+        std::weak_ptr<PeriodicTask> weakSelf{shared_from_this()};
         timer_.expires_from_now(boost::posix_time::millisec(periodMs_));
-        timer_.async_wait([this, self](const ErrorCode& ec) { handleTimeout(ec); });
+        timer_.async_wait([weakSelf](const ErrorCode& ec) {

Review Comment:
   I didn't get it why did you mention the destructor. Using `weak_ptr` here is to avoid a cyclic reference count case. Each object managed by a `shared_ptr` could cause cyclic reference. Using `weak_ptr` is a best practice for it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org