fix memory leak/bug in torrent::use_interface

This commit is contained in:
Arvid Norberg
2012-05-03 04:22:14 +00:00
parent cf49986e1a
commit 56c05f9671

View File

@@ -2068,14 +2068,15 @@ namespace libtorrent
m_net_interfaces.clear(); m_net_interfaces.clear();
char* str = strdup(net_interfaces.c_str()); char* str = strdup(net_interfaces.c_str());
char* ptr = str;
while (str) while (ptr)
{ {
char* space = strchr(str, ','); char* space = strchr(ptr, ',');
if (space) *space++ = 0; if (space) *space++ = 0;
error_code ec; error_code ec;
address a(address::from_string(str, ec)); address a(address::from_string(ptr, ec));
str = space; ptr = space;
if (ec) continue; if (ec) continue;
m_net_interfaces.push_back(tcp::endpoint(a, 0)); m_net_interfaces.push_back(tcp::endpoint(a, 0));
} }
@@ -5833,9 +5834,9 @@ namespace libtorrent
for (std::set<peer_connection*>::iterator i = m_connections.begin() for (std::set<peer_connection*>::iterator i = m_connections.begin()
, end(m_connections.end()); i != end; ++i) , end(m_connections.end()); i != end; ++i)
{ {
peer_connection* p = *i; peer_connection* peer = *i;
if (!p->is_connecting()) continue; if (!peer->is_connecting()) continue;
p->disconnect(errors::too_many_connections); peer->disconnect(errors::too_many_connections);
break; break;
} }
} }