Segfault on call to boost::ip::tcp::resolver::query
Hopefully I provided the useful info, thanks.
Backtrace
(gdb) run
Starting program: D:\C++\fail/ircserver.exe
[New thread 4968.0x2f40]
[New thread 4968.0x2cdc]
Program received signal SIGSEGV, Segmentation fault.
Irc::Client::getIP (this=0xbaadf00d)
    at D:/Dev-Cpp/include/boost/smart_ptr/shared_ptr.hpp:409
409             BOOST_ASSERT(px != 0);
(gdb) bt
#0  Irc::Client::getIP (this=0xbaadf00d)
    at D:/Dev-Cpp/include/boost/smart_ptr/shared_ptr.hpp:409
#1  0x004063c9 in Irc::Client::getHostName (this=0xbaadf00d)
    at D:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bit
s/basic_string.h:1456
#2  0x0041658d in Irc::User::setHost (this=0x3d40a0) at src/user.cpp:320
#3  0x0041136a in Irc::User::User (this=0x3d40a0, _name=@0x3d406c,
    _client=0x3d3ee0) at src/user.cpp:21
#4  0x0040c96d in main (argc=1, argv=0x3d2568) at src/main.cpp:47
(gdb)
src/user.cpp:320
// ...
void Irc::User::setHost()
{
    if (!client)
        return;
    if (!client->getHostName().empty())  // line 320
        host = client->getHostName();
    else
        host = client->getIP();
    //TODO
}
/src/user.cpp:21
Irc::User::User(const std::string& _name, Client* _client)
    : name(_name), client(client)
{
    joinTime = time(NULL);
    type = UT_NONE;
    idle = 0;
    setHost();  // line 21
    ident = name;
    IP = client->getIP();
    addEvent(1, onIdle);
}
main.cpp:47
user = new Irc::User(splited[1], it->second.get());
client.cpp:getHostName
std::string Irc::Client::getHostName()
{
    boost::asio::ip::tcp::resolver::query query(getIP(), SERVER_PORT_STRING); //this line
    boost::asio::ip::tcp::resolver resolver(*m_service);
    boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
    boost::asio::ip::tcp::resolver::iterator end;
    boost::system::error_code error = boost::asio::error::host_not_found;
    while (error && it开发者_如何学Pythonerator != end)
        *iterator++;
    if (error)
        return std::string();
    return "Found It";
}
client.cpp:getIP
boost::asio::ip::tcp::endpoint remote_ep = sock->remote_endpoint();
boost::asio::ip::address remote_ad = remote_ep.address();
return remote_ad.to_string();
0x004063c9 in Irc::Client::getHostName (this=0xbaadf00d)
at D:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bit
On Windows, this=0xbaadf00d means that *this is not properly initialized. In this case, I suspect that's because of the line client(client) in the definition of Irc::User::User, which should read client(_client) instead.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论