LocationQueryPrivate should check if a valid location provider was returned
LocationQueryPrivate
constructor creates a locationSource
member by calling QGeoPositionInfoSource::createDefaultSource()
to create a QGeoPositionInfoSource
object and then immediately calls locationSource->stopUpdates()
in the first line of the constructor:
LocationQueryPrivate::LocationQueryPrivate(LocationQuery *parent)
: QObject(parent)
, manager(new QNetworkAccessManager(this))
, locationSource(QGeoPositionInfoSource::createDefaultSource(this))
{
locationSource->stopUpdates();
connect(locationSource, &QGeoPositionInfoSource::positionUpdated, this, &LocationQueryPrivate::positionUpdated);
connect(this, &LocationQueryPrivate::queryFinished, parent, &LocationQuery::queryFinished);
connect(this, &LocationQueryPrivate::queryError, parent, &LocationQuery::queryError);
connect(this, &LocationQueryPrivate::located, parent, &LocationQuery::located);
}
But QGeoPositionInfoSource::createDefaultSource() will return null if no valid positioning source is found:
QGeoPositionInfoSource *QGeoPositionInfoSource::createDefaultSource(const QVariantMap ¶meters, QObject *parent)
{
QList<QJsonObject> plugins = QGeoPositionInfoSourcePrivate::pluginsSorted();
foreach (const QJsonObject &obj, plugins) {
if (obj.value(QStringLiteral("Position")).isBool()
&& obj.value(QStringLiteral("Position")).toBool()) {
QGeoPositionInfoSource *source = createSource_real(obj, parameters, parent);
if (source)
return source;
}
}
return nullptr;
}
This will make applications trying to create a KWeatherCore::LocationQuery
object crash with a segfault because the LocationQuery
creator will call locationSource->stopUpdates()
on a null locationSource
when no location providers are found.
This is the case for example for KWeather when clicking on Add current location.