From 099afba8a7f7cda82d7c2dc84ebdea14c16c11b7 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 10 Sep 2017 23:23:11 +0200 Subject: [PATCH] Found during T149, use QScopedPointer to destroy QNetworkReply --- src/plugins/weatherdata/gfs/weatherdatagfs.cpp | 13 ++++++++----- src/plugins/weatherdata/gfs/weatherdatagfs.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp index 2b08313c8..d8f889669 100644 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp +++ b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp @@ -99,16 +99,19 @@ namespace BlackWxPlugin emit fetchingFinished(); } - void CWeatherDataGfs::ps_parseGfsFile(QNetworkReply *reply) + void CWeatherDataGfs::ps_parseGfsFile(QNetworkReply *nwReplyPtr) { - m_gribData = reply->readAll(); + // wrap pointer, make sure any exit cleans up reply + // required to use delete later as object is created in a different thread + QScopedPointer nwReply(nwReplyPtr); + + m_gribData = nwReply->readAll(); Q_ASSERT_X(!m_parseGribFileWorker, Q_FUNC_INFO, "Worker already running"); m_parseGribFileWorker = BlackMisc::CWorker::fromTask(this, "parseGribFile", [this]() { parseGfsFileImpl(m_gribData); }); m_parseGribFileWorker->then(this, &CWeatherDataGfs::ps_fetchingWeatherDataFinished); - reply->deleteLater(); } QUrl CWeatherDataGfs::getDownloadUrl() const @@ -211,7 +214,7 @@ namespace BlackWxPlugin g2int iseek = 0; for (;;) { - if(QThread::currentThread()->isInterruptionRequested()) { return; } + if (QThread::currentThread()->isInterruptionRequested()) { return; } // Search next grib field g2int lskip = 0; @@ -260,7 +263,7 @@ namespace BlackWxPlugin for (const GfsGridPoint &gfsGridPoint : as_const(m_gfsWeatherGrid)) { - if(QThread::currentThread()->isInterruptionRequested()) { return; } + if (QThread::currentThread()->isInterruptionRequested()) { return; } CTemperatureLayerList temperatureLayers; diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.h b/src/plugins/weatherdata/gfs/weatherdatagfs.h index f35359c2a..3fd8cb5f1 100644 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.h +++ b/src/plugins/weatherdata/gfs/weatherdatagfs.h @@ -58,7 +58,7 @@ namespace BlackWxPlugin void ps_fetchingWeatherDataFinished(); //! Parsing - void ps_parseGfsFile(QNetworkReply *reply); + void ps_parseGfsFile(QNetworkReply *nwReplyPtr); private: enum Grib2CloudLevel