title: Boost.Asio segfault, no idea why
body: <p>This is a SSCCE from my Boost.Asio project based on the examples. It took me about an hour to track the bug down to this:</p>
  
  <pre><code>#include &lt;boost/bind.hpp&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  
  class Connection  {
  public:
      Connection(boost::asio::io_service&amp; io_service) : socket(io_service) {}
  
  private:
      boost::asio::ip::tcp::socket socket;
  };
  
  class Server {
  public:
      Server() : signal_monitor(io_service) {
          signal_monitor.add(SIGINT);
          signal_monitor.add(SIGTERM);
  
          signal_monitor.async_wait(
              boost::bind(&amp;Server::handle_signal_caught, this)
          );
      }
  
      void run() {
          // comment out the next line and there's no segfault
          connection.reset(new Connection(io_service));
  
          io_service.run();
      }
  
  private:
      void handle_signal_caught() {
          io_service.stop();
      }
  
      boost::shared_ptr&lt;Connection&gt; connection;
      boost::asio::io_service io_service;
      boost::asio::signal_set signal_monitor;
  };
  
  int main(int argc, char **argv) {
      Server server;
      server.run();
  
      return 0;
  }
  </code></pre>
  
  <p>When I send a signal (ctrl+C) the program segfaults instead of shutting down nicely. I've spent the last half hour looking at this, but I simply do not see why this would segfault, can any of you guys spot the issue?</p>