]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2871] Don't preserve pointers to stack
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Mon, 8 Apr 2013 12:15:45 +0000 (14:15 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Wed, 24 Apr 2013 15:40:19 +0000 (17:40 +0200)
It seems the boost::function created from functor takes just the
reference. This led to taking address of temporary and failing later on.
Allocate new object manually and delete it after it was used.

src/bin/resolver/bench/fake_resolution.cc

index baa7d24203a7e6c51ebbca5675c60ee996bb3662..d406a7076f59b0302e5583dd7b433d11a53bedfc 100644 (file)
@@ -143,15 +143,16 @@ public:
         callback_(callback),
         timer_(timer)
     {}
-    void operator()() {
+    void trigger() {
         query_->outstanding_ = false;
         callback_();
+        // We are not needed any more.
+        delete this;
     }
 private:
     FakeQuery* const query_;
     const FakeQuery::StepCallback callback_;
-    // Just to hold it alive before the callback is called (or discarded for
-    // some reason, like destroying the service).
+    // Just to hold it alive before the callback is called.
     const boost::shared_ptr<asiolink::IntervalTimer> timer_;
 };
 
@@ -162,8 +163,8 @@ FakeInterface::scheduleUpstreamAnswer(FakeQuery* query,
 {
     const boost::shared_ptr<asiolink::IntervalTimer>
         timer(new asiolink::IntervalTimer(service_));
-    UpstreamQuery q(query, callback, timer);
-    timer->setup(q, msec);
+    UpstreamQuery* q(new UpstreamQuery(query, callback, timer));
+    timer->setup(boost::bind(&UpstreamQuery::trigger, q), msec);
 }
 
 }