From 7f7c55a293a5b500f5c56670d9ca80c5c1bd0e76 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 1 May 2011 10:27:43 -0400 Subject: [PATCH] Only delete qnam objects in liblastfm2 that it creates itself --- thirdparty/liblastfm2/src/ws/ws.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/thirdparty/liblastfm2/src/ws/ws.cpp b/thirdparty/liblastfm2/src/ws/ws.cpp index 232824ddd..0625218e8 100644 --- a/thirdparty/liblastfm2/src/ws/ws.cpp +++ b/thirdparty/liblastfm2/src/ws/ws.cpp @@ -26,9 +26,12 @@ #include #include #include +#include #include -static QMap< QThread*, QNetworkAccessManager* > threadNamMap; +static QMap< QThread*, QNetworkAccessManager* > threadNamHash; +static QMap< QThread*, bool > ourNamHash; +static QMutex namAccessMutex; QString lastfm::ws::host() @@ -193,29 +196,33 @@ lastfm::ws::parse( QNetworkReply* reply ) throw( ParseError ) QNetworkAccessManager* lastfm::nam() { + QMutexLocker l( &namAccessMutex ); QThread* thread = QThread::currentThread(); - if ( !threadNamMap.contains( thread ) ) + if ( !threadNamHash.contains( thread ) ) { NetworkAccessManager* newNam = new NetworkAccessManager(); - threadNamMap[thread] = newNam; + threadNamHash[thread] = newNam; + ourNamHash[thread] = true; return newNam; } - return threadNamMap[thread]; + return threadNamHash[thread]; } void lastfm::setNetworkAccessManager( QNetworkAccessManager* nam ) { + if ( !nam ) + return; + + QMutexLocker l( &namAccessMutex ); QThread* thread = QThread::currentThread(); - if ( threadNamMap.contains( thread ) ) - { - delete threadNamMap[thread]; - threadNamMap[thread] = 0; - } + if ( threadNamHash.contains( thread ) && ourNamHash.contains( thread ) && ourNamHash[thread] ) + delete threadNamHash[thread]; - threadNamMap[thread] = nam; + threadNamHash[thread] = nam; + ourNamHash[thread] = false; }