Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
[error] dup temporary value in what(). Fixes MER#1381
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Zalevskiy <denis.zalevskiy@jolla.com>
  • Loading branch information
Denis Zalevskiy committed Oct 22, 2015
1 parent 1f81589 commit cb58af8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions include/qtaround/error.hpp
Expand Up @@ -26,12 +26,13 @@ QString dump(T && t)
class Error : public std::exception
{
public:
Error(QVariantMap const &from) : m(from) {}
virtual ~Error() noexcept(true) {}
Error(QVariantMap const &from) : m(from), cstr(nullptr) {}
virtual ~Error() noexcept(true) { if (cstr) free(cstr); }
virtual const char* what() const noexcept(true);

QVariantMap m;
mutable QString s;
mutable char *cstr;
};

QDebug operator << (QDebug dst, error::Error const &src);
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -11,7 +11,7 @@ add_library(qtaround SHARED
qt5_use_modules(qtaround Core)
target_link_libraries(qtaround ${COR_LIBRARIES})
set_target_properties(qtaround PROPERTIES
SOVERSION 1
SOVERSION 2
VERSION ${VERSION}
)
install(TARGETS qtaround DESTINATION ${DST_LIB})
Expand Down
9 changes: 6 additions & 3 deletions src/util.cpp
Expand Up @@ -16,9 +16,12 @@ namespace qtaround {
namespace error {
const char* Error::what() const noexcept(true)
{
if (s.isEmpty())
s = dump(m);
return s.toUtf8();
if (!cstr) {
if (s.isEmpty())
s = dump(m);
cstr = strdup(s.toUtf8());
}
return cstr;
}

QDebug operator << (QDebug dst, error::Error const &src)
Expand Down

0 comments on commit cb58af8

Please sign in to comment.