diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2020-01-15 15:13:27 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2020-03-27 09:56:13 +0100 |
commit | ccfcf832862582cd0e7c6b33547c9bf9d3b47240 (patch) | |
tree | e5cdab2910b150bbc5da4a067187d44ee160b3e9 | |
parent | f16f4a231cd10867c10eb42fb456867469c93836 (diff) | |
download | qtlocation-ccfcf832862582cd0e7c6b33547c9bf9d3b47240.tar.gz |
winrt: Fix crash on exit
Using a static ComPtr<IGeoLocationStatics> in requestAccess might cause
a crash on exit as this pointer might be cleaned up after the application
has exited. Make sure, that this pointer is deleted together with the
rest by making it part of the d pointer.
Fixes: QTBUG-80711
Change-Id: I93c09a4549967195101de07b3cef430f8cd52229
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r-- | src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp b/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp index a9cc164f..28a405c3 100644 --- a/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp +++ b/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp @@ -115,6 +115,7 @@ enum class InitializationState { class QGeoPositionInfoSourceWinRTPrivate { public: ComPtr<IGeolocator> locator; + mutable ComPtr<IGeolocatorStatics> statics; QTimer periodicTimer; QTimer singleUpdateTimer; QGeoPositionInfo lastPosition; @@ -638,21 +639,21 @@ HRESULT QGeoPositionInfoSourceWinRT::onStatusChanged(IGeolocator *, IStatusChang bool QGeoPositionInfoSourceWinRT::requestAccess() const { + Q_D(const QGeoPositionInfoSourceWinRT); qCDebug(lcPositioningWinRT) << __FUNCTION__; GeolocationAccessStatus accessStatus; - static ComPtr<IGeolocatorStatics> statics; ComPtr<IAsyncOperation<GeolocationAccessStatus>> op; HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([&op]() { + hr = QEventDispatcherWinRT::runOnXamlThread([&op, d]() { HRESULT hr; - if (!statics) { + if (!d->statics) { hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Geolocation_Geolocator).Get(), - IID_PPV_ARGS(&statics)); + IID_PPV_ARGS(&d->statics)); RETURN_HR_IF_FAILED("Could not access Geolocation Statics."); } - hr = statics->RequestAccessAsync(&op); + hr = d->statics->RequestAccessAsync(&op); return hr; }); if (FAILED(hr)) { |