svn2github/libtorrent-1_0_x — pull request #1 by davidchappelle (2014-11-28 21:25:37+00:00)
Title: Do not store reference to user agent string in upnp class.

We cannot be guaranteed that the upnp class will be constructed
from a string object that will outlive the upnp class scope. For
example:

std::unique_ptr upnp;
try {
upnp.reset(new libtorrent::upnp(
io_service, connection_queue,
endpoint.address(), "user-agent",
&portmap_callback, &log_callback, false));

In this particular case an implicit temporary std::string is
constructed to satisfy the constructors parameter type. If we
try and store this internally as a reference to a std::string
we end up with a dangling reference as the temporary std::string
from the constructor call is destroyed as soon as the call completes.
In my particualr case this was causing some very wierd behaviour on
the router that I was mapping a port on. Since the user agent is used
as part of the description field in a mapping request we were in some
cases sending binary rubbish which the router was not dealing with very
graciously.