From 452fd21d157c2a33893b2c036d8bc7a730841b49 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 17 Apr 2009 16:49:56 +0000 Subject: [PATCH] (trunk libT) #1996: Regression: Crash on shutdown when IPv6 is unavailable --- libtransmission/session.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libtransmission/session.c b/libtransmission/session.c index ac5177a9e..48dc5667d 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -308,6 +308,9 @@ const tr_socketList * tr_getSessionBindSockets( const tr_session * session ); void tr_sessionGetSettings( tr_session * s, struct tr_benc * d ) { + const char * val; + const tr_address * addr; + assert( tr_bencIsDict( d ) ); tr_bencDictReserve( d, 30 ); @@ -356,10 +359,14 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d ) tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED, tr_sessionGetSpeedLimit( s, TR_UP ) ); tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_UP ) ); tr_bencDictAddInt ( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, s->uploadSlotsPerTorrent ); - tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV4, - tr_ntop_non_ts( tr_socketListGetType( tr_getSessionBindSockets( s ), TR_AF_INET ) ) ); - tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6, - tr_ntop_non_ts( tr_socketListGetType( tr_getSessionBindSockets( s ), TR_AF_INET6 ) ) ); + + addr = tr_socketListGetType( tr_getSessionBindSockets( s ), TR_AF_INET ); + val = addr ? tr_ntop_non_ts( addr ) : TR_DEFAULT_BIND_ADDRESS_IPV4; + tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV4, val ); + + addr = tr_socketListGetType( tr_getSessionBindSockets( s ), TR_AF_INET6 ); + val = addr ? tr_ntop_non_ts( addr ) : TR_DEFAULT_BIND_ADDRESS_IPV6; + tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6, val ); } void