From ccaaa0f9d0268142f3678476655562cb5eb1dfef Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Sun, 17 Jul 2016 18:10:05 +0200 Subject: Fix potential memory leak in QGeoTiledMappingManagerEngine Currently setTileFetcher and setTileCache behave in two different ways, while the former relies on having the parent set properly for the destruction, the latter is deleted on destruction With this patch handles both pointers are handled in the same way: they are parented in the setter, and the destruction is left to the qobject destructor. Change-Id: Iaf11a12cd95088fd2268817b39fb9d58311b1812 Reviewed-by: Alex Blasche --- src/location/maps/qgeotiledmappingmanagerengine.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/location/maps/qgeotiledmappingmanagerengine.cpp b/src/location/maps/qgeotiledmappingmanagerengine.cpp index 4e777ab2..dc5f1889 100644 --- a/src/location/maps/qgeotiledmappingmanagerengine.cpp +++ b/src/location/maps/qgeotiledmappingmanagerengine.cpp @@ -65,11 +65,16 @@ QGeoTiledMappingManagerEngine::~QGeoTiledMappingManagerEngine() delete d_ptr; } - +/*! + Sets the tile fetcher. Takes ownership of the QObject. +*/ void QGeoTiledMappingManagerEngine::setTileFetcher(QGeoTileFetcher *fetcher) { Q_D(QGeoTiledMappingManagerEngine); + if (d->fetcher_) + d->fetcher_->deleteLater(); + fetcher->setParent(this); d->fetcher_ = fetcher; qRegisterMetaType(); @@ -275,10 +280,14 @@ void QGeoTiledMappingManagerEngine::setCacheHint(QGeoTiledMappingManagerEngine:: d->cacheHint_ = cacheHint; } +/*! + Sets the tile cache. Takes ownership of the QObject. +*/ void QGeoTiledMappingManagerEngine::setTileCache(QAbstractGeoTileCache *cache) { Q_D(QGeoTiledMappingManagerEngine); Q_ASSERT_X(!d->tileCache_, Q_FUNC_INFO, "This should be called only once"); + cache->setParent(this); d->tileCache_ = cache; } @@ -312,7 +321,6 @@ QGeoTiledMappingManagerEnginePrivate::QGeoTiledMappingManagerEnginePrivate() QGeoTiledMappingManagerEnginePrivate::~QGeoTiledMappingManagerEnginePrivate() { - delete tileCache_; } #include "moc_qgeotiledmappingmanagerengine_p.cpp" -- cgit v1.2.1