From 20de7a1a811326aedf46648cd3382d383ad388cc Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 4 Feb 2016 17:13:01 +0000 Subject: [PATCH] Don't leak AudioScrobbler. --- src/internet/lastfm/lastfmservice.cpp | 12 +++++------- src/internet/lastfm/lastfmservice.h | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/internet/lastfm/lastfmservice.cpp b/src/internet/lastfm/lastfmservice.cpp index 3ec89119a..cb21e82b8 100644 --- a/src/internet/lastfm/lastfmservice.cpp +++ b/src/internet/lastfm/lastfmservice.cpp @@ -79,7 +79,6 @@ const char* LastFMService::kAuthLoginUrl = LastFMService::LastFMService(Application* app, QObject* parent) : Scrobbler(parent), - scrobbler_(nullptr), already_scrobbled_(false), scrobbling_enabled_(false), connection_problems_(false), @@ -185,8 +184,7 @@ void LastFMService::AuthenticateReplyFinished(QNetworkReply* reply) { } // Invalidate the scrobbler - it will get recreated later - delete scrobbler_; - scrobbler_ = nullptr; + scrobbler_.reset(nullptr); emit AuthenticationComplete(true, QString()); } @@ -289,16 +287,16 @@ bool LastFMService::InitScrobbler() { if (!IsAuthenticated() || !IsScrobblingEnabled()) return false; if (!scrobbler_) - scrobbler_ = new lastfm::Audioscrobbler(kAudioscrobblerClientId); + scrobbler_.reset(new lastfm::Audioscrobbler(kAudioscrobblerClientId)); // reemit the signal since the sender is private #ifdef HAVE_LIBLASTFM1 - connect(scrobbler_, SIGNAL(scrobblesSubmitted(QList)), + connect(scrobbler_.get(), SIGNAL(scrobblesSubmitted(QList)), SIGNAL(ScrobbleSubmitted())); - connect(scrobbler_, SIGNAL(nowPlayingError(int, QString)), + connect(scrobbler_.get(), SIGNAL(nowPlayingError(int, QString)), SIGNAL(ScrobbleError(int))); #else - connect(scrobbler_, SIGNAL(status(int)), SLOT(ScrobblerStatus(int))); + connect(scrobbler_.get(), SIGNAL(status(int)), SLOT(ScrobblerStatus(int))); #endif return true; } diff --git a/src/internet/lastfm/lastfmservice.h b/src/internet/lastfm/lastfmservice.h index d777be976..b18394169 100644 --- a/src/internet/lastfm/lastfmservice.h +++ b/src/internet/lastfm/lastfmservice.h @@ -82,7 +82,7 @@ class LastFMService : public Scrobbler { void ShowConfig(); void ToggleScrobbling(); - signals: +signals: void TokenReceived(bool success, const QString& token); void AuthenticationComplete(bool success, const QString& error_message); void ScrobblingEnabledChanged(bool value); @@ -111,7 +111,7 @@ class LastFMService : public Scrobbler { static QUrl FixupUrl(const QUrl& url); private: - lastfm::Audioscrobbler* scrobbler_; + std::unique_ptr scrobbler_; lastfm::Track last_track_; lastfm::Track next_metadata_; bool already_scrobbled_;