Skip to content

Commit

Permalink
Try to prevent some segfaults in MythDownloadManger
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartm committed Jan 25, 2012
1 parent 8e26fd6 commit 4f11822
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion mythtv/libs/libmythbase/mythdownloadmanager.cpp
Expand Up @@ -251,8 +251,13 @@ void MythDownloadManager::run(void)
if (!m_downloadQueue.isEmpty())
{
MythDownloadInfo *dlInfo = m_downloadQueue.front();
QUrl qurl(dlInfo->m_url);

m_downloadQueue.pop_front();

if (!dlInfo)
continue;

QUrl qurl(dlInfo->m_url);
if (m_downloadInfos.contains(qurl.toString()))
{
// Push request to the end of the queue to let others process.
Expand Down Expand Up @@ -448,6 +453,7 @@ QNetworkReply *MythDownloadManager::download(const QString &url,
dlInfo->m_reply = NULL;

delete dlInfo;
dlInfo = NULL;

if (ok && reply)
return reply;
Expand Down Expand Up @@ -573,6 +579,9 @@ void MythDownloadManager::downloadRemoteFile(MythDownloadInfo *dlInfo)
*/
void MythDownloadManager::downloadQNetworkRequest(MythDownloadInfo *dlInfo)
{
if (!dlInfo)
return;

static const char dateFormat[] = "ddd, dd MMM yyyy hh:mm:ss 'GMT'";
QUrl qurl(dlInfo->m_url);
QNetworkRequest request;
Expand Down Expand Up @@ -659,6 +668,9 @@ void MythDownloadManager::downloadQNetworkRequest(MythDownloadInfo *dlInfo)
*/
bool MythDownloadManager::downloadNow(MythDownloadInfo *dlInfo, bool deleteInfo)
{
if (!dlInfo)
return false;

dlInfo->m_syncMode = true;

m_infoLock->lock();
Expand Down Expand Up @@ -697,7 +709,10 @@ bool MythDownloadManager::downloadNow(MythDownloadInfo *dlInfo, bool deleteInfo)
dlInfo->m_reply->abort();
}
else if (deleteInfo)
{
delete dlInfo;
dlInfo = NULL;
}

m_infoLock->unlock();

Expand Down Expand Up @@ -725,6 +740,7 @@ void MythDownloadManager::cancelDownload(const QString &url)
dlInfo->m_reply->abort();
lit.remove();
delete dlInfo;
dlInfo = NULL;
}
}

Expand All @@ -738,6 +754,7 @@ void MythDownloadManager::cancelDownload(const QString &url)
}
m_downloadInfos.remove(url);
delete dlInfo;
dlInfo = NULL;
}
}

Expand Down Expand Up @@ -851,6 +868,9 @@ void MythDownloadManager::downloadFinished(QNetworkReply* reply)
*/
void MythDownloadManager::downloadFinished(MythDownloadInfo *dlInfo)
{
if (!dlInfo)
return;

static const char dateFormat[] = "ddd, dd MMM yyyy hh:mm:ss 'GMT'";
QNetworkReply *reply = dlInfo->m_reply;

Expand Down Expand Up @@ -994,6 +1014,7 @@ void MythDownloadManager::downloadFinished(MythDownloadInfo *dlInfo)
}

delete dlInfo;
dlInfo = NULL;
}

m_queueWaitCond.wakeAll();
Expand Down

0 comments on commit 4f11822

Please sign in to comment.