]> granicus.if.org Git - transmission/commitdiff
(gtk) fix potential invalid memory read on shutdown
authorCharles Kerr <charles@transmissionbt.com>
Thu, 17 Apr 2008 20:35:18 +0000 (20:35 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 17 Apr 2008 20:35:18 +0000 (20:35 +0000)
gtk/main.c
gtk/tr-core.c
gtk/tr-core.h
libtransmission/session.c

index b0cb4187e0a7f325454551676cb145e16f28f13e..64f937c1eccd2320238518d0f510137390c00702 100644 (file)
@@ -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 )
index d84d78a483c4bcb450726a0a79134759b81d0fbd..99698706dac1b350500f36454af28e987be9155d 100644 (file)
@@ -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 );
index da3c0a679ecf1566c7577b422dd0ec78e2607958..3ed5e240fb249b254e62364797860e4fd7d457fc 100644 (file)
@@ -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 );
 
index a94326c5579700ed0236aafead41ab598a40392c..4de4c30e800d526b57a7dd20d96f4e731f51dd64 100644 (file)
@@ -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