Skip to content

Commit

Permalink
Fix a couple potential segfaults in MythDownloadManager.
Browse files Browse the repository at this point in the history
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 619d87b
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions mythtv/libs/libmythbase/mythdownloadmanager.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 619d87b

Please sign in to comment.