From be1866db10d6d6397dcb36dea487d213cf4bdc3e Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Sun, 9 Jan 2022 14:30:06 +0800 Subject: [PATCH] fix:resource scheme handler received finished signal twice,more likely to crash the webengine. --- article_netmgr.cc | 13 ++++++++----- article_netmgr.hh | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/article_netmgr.cc b/article_netmgr.cc index 061bc57a..31cafe3f 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -438,6 +438,8 @@ ArticleResourceReply::ArticleResourceReply( QObject * parent, { connect( this, SIGNAL( readyReadSignal() ), this, SLOT( readyReadSlot() ), Qt::QueuedConnection ); + connect( this, SIGNAL( finishedSignal() ), + this, SLOT( finishedSlot() ), Qt::QueuedConnection ); emit readyReadSignal(); @@ -446,10 +448,6 @@ ArticleResourceReply::ArticleResourceReply( QObject * parent, emit finishedSignal(); GD_DPRINTF( "In-place finish.\n" ); } - else{ - connect( this, SIGNAL( finishedSignal() ), - this, SLOT( finishedSlot() ), Qt::QueuedConnection ); - } } } @@ -527,7 +525,12 @@ void ArticleResourceReply::finishedSlot() setError(ContentNotFoundError, "content not found"); } - emit finished(); + //prevent sent multi times. + if (!finishSignalSent.loadAcquire()) + { + finishSignalSent.ref(); + emit finished(); + } } BlockedNetworkReply::BlockedNetworkReply( QObject * parent ): QNetworkReply( parent ) diff --git a/article_netmgr.hh b/article_netmgr.hh index ea903b27..08d59de2 100644 --- a/article_netmgr.hh +++ b/article_netmgr.hh @@ -137,6 +137,8 @@ class ArticleResourceReply: public QNetworkReply sptr< Dictionary::DataRequest > req; qint64 alreadyRead; + QAtomicInt finishSignalSent; + public: ArticleResourceReply( QObject * parent,