From 3e88159e9fa6ccd52bd5ad07b1baf3603fa7b70e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 17 Apr 2008 20:35:18 +0000 Subject: [PATCH] (gtk) fix potential invalid memory read on shutdown --- gtk/main.c | 2 +- gtk/tr-core.c | 12 ++++++++++++ gtk/tr-core.h | 2 ++ libtransmission/session.c | 15 +++++++++------ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/gtk/main.c b/gtk/main.c index b0cb4187e..64f937c1e 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -550,7 +550,7 @@ quitThreadFunc( gpointer gdata ) { struct cbdata * cbdata = gdata; - tr_close( tr_core_handle( cbdata->core ) ); + tr_core_close( cbdata->core ); /* shutdown the gui */ if( cbdata->prefs ) diff --git a/gtk/tr-core.c b/gtk/tr-core.c index d84d78a48..99698706d 100644 --- a/gtk/tr-core.c +++ b/gtk/tr-core.c @@ -551,6 +551,17 @@ tr_core_new( void ) return core; } +void +tr_core_close( TrCore * core ) +{ + tr_handle * handle = tr_core_handle( core ); + if( handle ) + { + core->priv->handle = NULL; + tr_close( handle ); + } +} + GtkTreeModel * tr_core_model( TrCore * core ) { @@ -595,6 +606,7 @@ tr_core_get_stats( const TrCore * core, tr_torrentRates( core->priv->handle, &setme->clientDownloadSpeed, &setme->clientUploadSpeed ); + gtk_tree_model_foreach( core->priv->model, statsForeach, setme ); diff --git a/gtk/tr-core.h b/gtk/tr-core.h index da3c0a679..3ed5e240f 100644 --- a/gtk/tr-core.h +++ b/gtk/tr-core.h @@ -91,6 +91,8 @@ GType tr_core_get_type( void ); TrCore * tr_core_new( void ); +void tr_core_close( TrCore* ); + /* Return the model used without incrementing the reference count */ GtkTreeModel * tr_core_model( TrCore * self ); diff --git a/libtransmission/session.c b/libtransmission/session.c index a94326c55..4de4c30e8 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -362,14 +362,17 @@ tr_getGlobalPeerLimit( const tr_handle * handle UNUSED ) void tr_torrentRates( tr_handle * h, float * toClient, float * toPeer ) { - tr_globalLock( h ); + if( h ) + { + tr_globalLock( h ); - if( toClient ) - *toClient = tr_rcRate( h->download ); - if( toPeer ) - *toPeer = tr_rcRate( h->upload ); + if( toClient ) + *toClient = tr_rcRate( h->download ); + if( toPeer ) + *toPeer = tr_rcRate( h->upload ); - tr_globalUnlock( h ); + tr_globalUnlock( h ); + } } int