From: Michal 'vorner' Vaner Date: Mon, 8 Apr 2013 12:15:45 +0000 (+0200) Subject: [2871] Don't preserve pointers to stack X-Git-Tag: bind10-1.1.0beta2-release~8^2~10^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6700ecd585dac224bd92008fef7f6ee8a275d04b;p=thirdparty%2Fkea.git [2871] 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. --- diff --git a/src/bin/resolver/bench/fake_resolution.cc b/src/bin/resolver/bench/fake_resolution.cc index baa7d24203..d406a7076f 100644 --- a/src/bin/resolver/bench/fake_resolution.cc +++ b/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 timer_; }; @@ -162,8 +163,8 @@ FakeInterface::scheduleUpstreamAnswer(FakeQuery* query, { const boost::shared_ptr 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); } }