From 80867af8231f0dae6b10449017d0b77c54e01064 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 7 Sep 2013 15:39:05 +1000 Subject: [PATCH] Don't return a free'd pointer from Echonest::ParseError::what(). Might fix a crash on Windows when there are no echonest results. (cherry picked from commit 4ec7c0952229df130136a589147a914b68d72abf) --- 3rdparty/libechonest/Config.cpp | 44 +++++++++++++++++++-------------- 3rdparty/libechonest/Config.h | 3 +++ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/3rdparty/libechonest/Config.cpp b/3rdparty/libechonest/Config.cpp index d355b60b8..e26202c2a 100644 --- a/3rdparty/libechonest/Config.cpp +++ b/3rdparty/libechonest/Config.cpp @@ -45,34 +45,21 @@ QUrl Echonest::baseGetQuery(const QByteArray& type, const QByteArray& method) Echonest::ParseError::ParseError(Echonest::ErrorType error): exception() { type = error; + whatData = createWhatData(); } Echonest::ParseError::ParseError(Echonest::ErrorType error, const QString& text): exception() { type = error; extraText = text; + whatData = createWhatData(); } - -Echonest::ParseError::~ParseError() throw() -{} - -Echonest::ErrorType Echonest::ParseError::errorType() const throw() +QByteArray Echonest::ParseError::createWhatData() const throw() { - return type; -} - -void Echonest::ParseError::setNetworkError( QNetworkReply::NetworkError error ) throw() -{ - nError = error; -} - -const char* Echonest::ParseError::what() const throw() -{ - - // If we have specific error text, return that first + // If we have specific error text, use that first if( !extraText.isEmpty() ) - return extraText.toLatin1().constData(); + return extraText.toLatin1(); switch( type ) { @@ -99,7 +86,26 @@ const char* Echonest::ParseError::what() const throw() case UnknownParseError: return "Unknown Parse Error"; } - return ""; + return QByteArray(); +} + + +Echonest::ParseError::~ParseError() throw() +{} + +Echonest::ErrorType Echonest::ParseError::errorType() const throw() +{ + return type; +} + +void Echonest::ParseError::setNetworkError( QNetworkReply::NetworkError error ) throw() +{ + nError = error; +} + +const char* Echonest::ParseError::what() const throw() +{ + return whatData.constData(); } diff --git a/3rdparty/libechonest/Config.h b/3rdparty/libechonest/Config.h index 312fd83e7..6bf23d781 100644 --- a/3rdparty/libechonest/Config.h +++ b/3rdparty/libechonest/Config.h @@ -74,9 +74,12 @@ namespace Echonest{ virtual const char* what() const throw (); private: + QByteArray createWhatData() const throw(); + ErrorType type; QString extraText; QNetworkReply::NetworkError nError; + QByteArray whatData; }; class ConfigPrivate;