]> granicus.if.org Git - transmission/commitdiff
Revert dd538539aa, fix RPC queue processing
authorMike Gelfand <mikedld@mikedld.com>
Sat, 15 Jul 2017 05:46:31 +0000 (08:46 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Sat, 15 Jul 2017 05:46:31 +0000 (08:46 +0300)
Queue callback for items returning no new future was never called leaving
queue alive and leading to memory leak in Qt client.

qt/RpcQueue.cc
qt/Session.cc

index 09484ee62a622b15955dbd22f7fff700be8818f4..c33f2e3af910b51d80345c78f6ab71e13c2e96fa 100644 (file)
@@ -72,9 +72,25 @@ void RpcQueue::runNext(RpcResponseFuture const& response)
 {
     assert(!myQueue.isEmpty());
 
-    auto next = myQueue.dequeue();
-    myNextErrorHandler = next.second;
-    myFutureWatcher.setFuture((next.first)(response));
+    RpcResponseFuture const oldFuture = myFutureWatcher.future();
+
+    while (true)
+    {
+        auto next = myQueue.dequeue();
+        myNextErrorHandler = next.second;
+        myFutureWatcher.setFuture((next.first)(response));
+
+        if (oldFuture != myFutureWatcher.future())
+        {
+            break;
+        }
+
+        if (myQueue.isEmpty())
+        {
+            deleteLater();
+            break;
+        }
+    }
 }
 
 void RpcQueue::run()
index 1a710cdf95ee221873e06f76c0cee4d49246192c..cea7fbd53517e281f115edf7033b82fa7c8acfa1 100644 (file)
@@ -995,7 +995,7 @@ void Session::addTorrent(AddData const& addMe, tr_variant* args, bool trashOrigi
             d->show();
         });
 
-    q->add([this, addMe, trashOriginal](RpcResponse const& r)
+    q->add([this, addMe](RpcResponse const& r)
         {
             tr_variant* dup;
             char const* str;
@@ -1010,13 +1010,17 @@ void Session::addTorrent(AddData const& addMe, tr_variant* args, bool trashOrigi
                 connect(d, SIGNAL(rejected()), d, SLOT(deleteLater()));
                 d->show();
             }
-            else if (trashOriginal && addMe.type == AddData::FILENAME)
+        });
+
+    if (trashOriginal && addMe.type == AddData::FILENAME)
+    {
+        q->add([this, addMe]()
             {
                 QFile original(addMe.filename);
                 original.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
                 original.remove();
-            }
-        });
+            });
+    }
 
     q->run();
 }