Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-127140

When using qnetworkaccessmanager as a temporary variable, the destructor of qnetworkaccessmanager may crash if it goes out of scope.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P1: Critical
    • None
    • 5.15
    • Network: HTTP
    • None
    • Windows 10 professional (19042.1586) Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz 16.0 GB 2.90 GHz qt5.15.2 win32
    • Windows

    Description

       

      	std::thread([=]		{			QStringList keys = json.keys();			QUrlQuery urlParam;			for (int i = 0; i < keys.count(); ++i)			{				QString key = keys.value(i);				if (json.value(key).isString())				{					urlParam.addQueryItem(key, json.value(key).toString());				}				else				{					urlParam.addQueryItem(key, QString::number(json.value(key).toInt()));				}			}            // qDebug() << __FUNCTION__ << __LINE__ << url.url() << urlParam.toString() << QDateTime::currentDateTime();			QUrl urlTemp(url);			urlTemp.setQuery(urlParam);
                  QNetworkRequest networkRequest;			networkRequest.setUrl(urlTemp);			networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
      			QEventLoop loop;			QTimer timer;			QNetworkAccessManager	networkManager;			QNetworkReply* pReply = networkManager.get(networkRequest);
      			connect(&timer, SIGNAL(timeout()), pReply, SLOT(abort()));			connect(this, SIGNAL(SignalStopRequest()), pReply, SLOT(abort()));			connect(pReply, SIGNAL(finished()), &loop, SLOT(quit()));
      			timer.setSingleShot(true);			timer.start(nTimeOut);			loop.exec();			do			{				if (!timer.isActive())				{                    // qDebug() << __FUNCTION__ << __LINE__ << "timeout" << url.url() << urlParam.toString() << QDateTime::currentDateTime();					emit SignalRequestTimeout();					break;				}
      				if (pReply->error() == QNetworkReply::OperationCanceledError)				{					emit SignalRequestCancel();					break;				}
      				log_info("async reply error:%s", pReply->errorString().toStdString().c_str());
      				QByteArray data = pReply->readAll();                // qDebug() << __FUNCTION__ << __LINE__ << url.url() << data << QDateTime::currentDateTime();				emit SignalRequestResult(data);			} while (0);		}).detach();

      I use qnetworkaccessmanager like above, but on its destruction there is a stack like the following.

      crashcore.dmp

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            manordheim Mårten Nordheim
            huangzhongyi huang zhongyi
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes