Skip to content
Permalink
Browse files

Fix a couple potential segfaults in MythDownloadManager.

In both GetLastModified() and download(QString,bool), we were
deleting the MythDownloadInfo* even when downloadNow() failed.  Whenever
downloadNow() fails, it sets a flag to allow downloadFinished() to
clean up as if the call was async instead of sync, so we only need to
delete our MythDownloadInfo* if the download succeeded.
  • Loading branch information
cpinkham committed Aug 8, 2013
1 parent 97240ef commit 619d87bdc8a2e3291bbf6b771345170507aaa2c0
Showing with 26 additions and 16 deletions.
  1. +26 −16 mythtv/libs/libmythbase/mythdownloadmanager.cpp
@@ -481,24 +481,28 @@ QNetworkReply *MythDownloadManager::download(const QString &url,
const bool reload)
{
MythDownloadInfo *dlInfo = new MythDownloadInfo;
QNetworkReply *reply = NULL;

dlInfo->m_url = url;
dlInfo->m_reload = reload;
dlInfo->m_syncMode = true;
dlInfo->m_processReply = false;

bool ok = downloadNow(dlInfo, false);

QNetworkReply *reply = dlInfo->m_reply;
if (downloadNow(dlInfo, false))
{
if (dlInfo->m_reply)
{
reply = dlInfo->m_reply;
// prevent dlInfo dtor from deleting the reply
dlInfo->m_reply = NULL;

if (reply)
dlInfo->m_reply = NULL;
delete dlInfo;

delete dlInfo;
dlInfo = NULL;
return reply;
}

if (ok && reply)
return reply;
delete dlInfo;
}

return NULL;
}
@@ -1394,15 +1398,21 @@ QDateTime MythDownloadManager::GetLastModified(const QString &url)
// Head request, we only want to inspect the headers
dlInfo->m_requestType = kRequestHead;

if (downloadNow(dlInfo, false) && dlInfo->m_reply)
if (downloadNow(dlInfo, false))
{
QVariant lastMod =
dlInfo->m_reply->header(QNetworkRequest::LastModifiedHeader);
if (lastMod.isValid())
result = lastMod.toDateTime().toUTC();
}
if (dlInfo->m_reply)
{
QVariant lastMod =
dlInfo->m_reply->header(
QNetworkRequest::LastModifiedHeader);
if (lastMod.isValid())
result = lastMod.toDateTime().toUTC();
}

delete dlInfo;
// downloadNow() will set a flag to trigger downloadFinished()
// to delete the dlInfo if the download times out
delete dlInfo;
}
}

LOG(VB_FILE, LOG_DEBUG, LOC + QString("GetLastModified('%1'): Result %2")

0 comments on commit 619d87b

Please sign in to comment.
You can’t perform that action at this time.