From 52ff94d9c8151e22bd3e0cd2aa94e0cd5f35546c Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 23 May 2015 19:33:20 +0200 Subject: [PATCH] lastfm: use sink argument and fix possible usage of m_service after delete --- src/actions.cpp | 2 +- src/lastfm.h | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 0405e474..6e16889b 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -2231,7 +2231,7 @@ void ShowArtistInfo::run() if (!artist.empty()) { - myLastfm->queueJob(LastFm::ArtistInfo(artist, Config.lastfm_preferred_language)); + myLastfm->queueJob(new LastFm::ArtistInfo(artist, Config.lastfm_preferred_language)); myLastfm->switchTo(); } # endif // HAVE_CURL_CURL_H diff --git a/src/lastfm.h b/src/lastfm.h index 7c77c6bf..0998d3ce 100644 --- a/src/lastfm.h +++ b/src/lastfm.h @@ -51,24 +51,22 @@ struct Lastfm: Screen, Tabbable virtual bool isMergable() OVERRIDE { return true; } template - void queueJob(ServiceT &&service) + void queueJob(ServiceT *service) { - typedef typename std::remove_reference::type ServiceNoRef; - - auto old_service = dynamic_cast(m_service.get()); + auto old_service = dynamic_cast(m_service.get()); // if the same service and arguments were used, leave old info - if (old_service != nullptr && *old_service == service) + if (old_service != nullptr && *old_service == *service) return; - - m_service = std::make_shared(std::forward(service)); - m_worker = boost::async(boost::launch::async, std::bind(&LastFm::Service::fetch, m_service.get())); - + + m_service = std::shared_ptr(service); + m_worker = boost::async(boost::launch::async, std::bind(&LastFm::Service::fetch, m_service)); + w.clear(); w << "Fetching information..."; w.flush(); m_title = ToWString(m_service->name()); } - + private: void getResult();