From cb3ccd5a764e27c7d615aab93f290a051aa9fa59 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 10 Feb 2016 00:21:31 +0100 Subject: [PATCH] Protect m_formats access with mutex in Result --- src/libtomahawk/Result.cpp | 13 ++++++++++++- src/libtomahawk/Result.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/Result.cpp b/src/libtomahawk/Result.cpp index 9afd75fba..6c4f7c347 100644 --- a/src/libtomahawk/Result.cpp +++ b/src/libtomahawk/Result.cpp @@ -529,12 +529,23 @@ Result::track() const } +QList< DownloadFormat > +Result::downloadFormats() const +{ + QMutexLocker lock( &s_mutex ); + + return m_formats; +} + + void Result::setDownloadFormats( const QList& formats ) { if ( formats.isEmpty() ) return; + QMutexLocker lock( &s_mutex ); + m_formats.clear(); foreach ( const DownloadFormat& format, formats ) { @@ -562,7 +573,7 @@ Result::setDownloadFormats( const QList& formats ) void Result::onSettingsChanged() { - if ( TomahawkSettings::instance()->downloadsPreferredFormat().toLower() != m_formats.first().extension.toLower() ) + if ( TomahawkSettings::instance()->downloadsPreferredFormat().toLower() != downloadFormats().first().extension.toLower() ) { setDownloadFormats( downloadFormats() ); emit updated(); diff --git a/src/libtomahawk/Result.h b/src/libtomahawk/Result.h index c989ecb85..8f7a8624d 100644 --- a/src/libtomahawk/Result.h +++ b/src/libtomahawk/Result.h @@ -131,7 +131,7 @@ public: track_ptr track() const; - QList downloadFormats() const { return m_formats; } + QList< DownloadFormat > downloadFormats() const; void setDownloadFormats( const QList& formats ); downloadjob_ptr downloadJob() const { return m_downloadJob; }