From 92ae10e3388b612bf035a30cd72c99a6720ff5f9 Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Sun, 29 May 2016 16:02:40 +0200 Subject: [PATCH] #148: fixed crash in queue script handling If multiple queue scripts were queued and the nzb-file was deleted before all scripts were executed the program may crash. --- daemon/extension/QueueScript.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/daemon/extension/QueueScript.cpp b/daemon/extension/QueueScript.cpp index 2f4ffdaa..17f4e4e1 100644 --- a/daemon/extension/QueueScript.cpp +++ b/daemon/extension/QueueScript.cpp @@ -416,7 +416,7 @@ void QueueScriptCoordinator::CheckQueue() Guard guard(m_queueMutex); NzbInfo* curNzbInfo = nullptr; - Queue::iterator itCurItem = m_queue.end(); + Queue::iterator itCurItem; for (Queue::iterator it = m_queue.begin(); it != m_queue.end(); ) { @@ -430,6 +430,12 @@ void QueueScriptCoordinator::CheckQueue() nzbInfo->GetMarkStatus() == NzbInfo::ksBad) { it = m_queue.erase(it); + if (curNzbInfo) + { + // process from the beginning, while "erase" invalidated "itCurItem" + curNzbInfo = nullptr; + it = m_queue.begin(); + } continue; } @@ -442,7 +448,7 @@ void QueueScriptCoordinator::CheckQueue() it++; } - if (itCurItem != m_queue.end()) + if (curNzbInfo) { m_curItem = std::move(*itCurItem); m_queue.erase(itCurItem);