Browse Source

Fix memory leak in BaseException (and derived exceptions)

tempestpy_adaptions
Joachim Klein 7 years ago
committed by cdehnert
parent
commit
3783ff6420
  1. 7
      src/storm/exceptions/BaseException.cpp
  2. 4
      src/storm/exceptions/BaseException.h

7
src/storm/exceptions/BaseException.cpp

@ -19,11 +19,8 @@ namespace storm {
}
const char* BaseException::what() const NOEXCEPT {
std::string errorString = this->stream.str();
char* result = new char[errorString.size() + 1];
result[errorString.size()] = '\0';
std::copy(errorString.begin(), errorString.end(), result);
return result;
errorString = this->stream.str();
return errorString.c_str();
}
}
}

4
src/storm/exceptions/BaseException.h

@ -46,6 +46,10 @@ namespace storm {
protected:
// This stream stores the message of this exception.
std::stringstream stream;
private:
// storage for the string backing the C string returned by what()
mutable std::string errorString;
};
} // namespace exceptions

Loading…
Cancel
Save