From de7c9d56d31e266d1e2c19bbcba5b748055f9bb5 Mon Sep 17 00:00:00 2001 From: "S. Razi Alavizadeh" Date: Tue, 29 Jan 2013 19:50:58 +0330 Subject: [PATCH] Fixed crash on choosing non-writable download location. --- src/lib/downloads/downloaditem.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/downloads/downloaditem.cpp b/src/lib/downloads/downloaditem.cpp index f367471f8..fdcc3f818 100644 --- a/src/lib/downloads/downloaditem.cpp +++ b/src/lib/downloads/downloaditem.cpp @@ -320,13 +320,19 @@ void DownloadItem::stop(bool askForDeleteFile) return; } m_downloadStopped = true; - QString host = m_reply ? m_reply->url().host() : m_ftpDownloader->url().host(); + QString host; + if (m_reply) { + host = m_reply->url().host(); + } + else if (m_ftpDownloader) { + host = m_ftpDownloader->url().host(); + } m_openAfterFinish = false; m_timer.stop(); if (m_reply) { m_reply->abort(); } - else { + else if (m_ftpDownloader) { m_ftpDownloader->abort(); m_ftpDownloader->close(); } @@ -454,8 +460,8 @@ void DownloadItem::error() ui->downloadInfo->setText(tr("Error: ") + m_reply->errorString()); } else if (m_ftpDownloader && m_ftpDownloader->error() != QFtp::NoError) { - ui->downloadInfo->setText(tr("Error: ") + m_ftpDownloader->errorString()); stop(false); + ui->downloadInfo->setText(tr("Error: ") + m_ftpDownloader->errorString()); } } @@ -464,9 +470,10 @@ void DownloadItem::updateDownload() #ifdef DOWNMANAGER_DEBUG qDebug() << __FUNCTION__ ; #endif - bool downoaderIsFinished = (m_reply && m_reply->isFinished()) - || (m_ftpDownloader && m_ftpDownloader->isFinished()); - if (ui->progressBar->maximum() == 0 && m_outputFile.isOpen() && downoaderIsFinished) { + // after caling stop() (from readyRead()) m_reply will be a dangling pointer, + // thus it should be checked after m_outputFile.isOpen() + if (ui->progressBar->maximum() == 0 && m_outputFile.isOpen() && + ((m_reply && m_reply->isFinished()) || (m_ftpDownloader && m_ftpDownloader->isFinished()))) { downloadProgress(0, 0); finished(); }