Browse Source

[2738] Don't preserve pointers to stack

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.
Michal 'vorner' Vaner 12 years ago
parent
commit
135070d34d
1 changed files with 6 additions and 5 deletions
  1. 6 5
      src/bin/resolver/bench/fake_resolution.cc

+ 6 - 5
src/bin/resolver/bench/fake_resolution.cc

@@ -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);
 }
 
 }