From 7516966db5a2c11c4d5acea0353a4b9a65f4267c Mon Sep 17 00:00:00 2001 From: Asias He Date: Tue, 5 May 2015 17:40:44 +0800 Subject: [PATCH] message: Fix passing by reference From Avi: ''' start() returns immediately, then the listen object is destroyed (it is on the stack), then the lambda runs. [&] is also very dangerous. ''' This fixes a bug in initialization of messaging_service. [asias@hjpc urchin]$ ./message --listen-address 127.0.0.100 listen =127.0.0.100 protocol::server::server: addr=127.0.0.100:7000 opts.reuse_address=1, _reuseport=1 messaging_service on cpu_id=0, ip=127.0.0.100, listen_address=127.0.0.100 protocol::server::server: addr=0.36.145.24:7000 opts.reuse_address=1, _reuseport=1 messaging_service on cpu_id=1, ip=0.36.145.24, listen_address=0.36.145.24 Messaging server listening on port 7000 ... --- tests/urchin/message.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/urchin/message.cc b/tests/urchin/message.cc index 5e8bd0dd0b..fd34d04183 100644 --- a/tests/urchin/message.cc +++ b/tests/urchin/message.cc @@ -175,11 +175,10 @@ int main(int ac, char ** av) { ("server", bpo::value(), "Server ip") ("listen-address", bpo::value()->default_value("0.0.0.0"), "IP address to listen") ("cpuid", bpo::value()->default_value(0), "Server cpuid"); - return app.run(ac, av, [&] { - auto&& config = app.configuration(); - auto listen = gms::inet_address(config["listen-address"].as()); - net::get_messaging_service().start(std::ref(listen)).then([&] () { - auto&& config = app.configuration(); + return app.run(ac, av, [&app] { + auto config = app.configuration(); + const gms::inet_address listen = gms::inet_address(config["listen-address"].as()); + net::get_messaging_service().start(listen).then([config] () { auto testers = new distributed; testers->start().then([testers]{ auto& server = net::get_local_messaging_service();