Bugfix for the Exception class.

This commit is contained in:
Gunnar Beutner 2012-05-21 12:57:44 +02:00
parent eae3d67f02
commit a420d1f801
2 changed files with 13 additions and 12 deletions

View File

@ -26,6 +26,7 @@ using namespace icinga;
*/ */
Exception::Exception(void) Exception::Exception(void)
{ {
m_Message = NULL;
} }
/** /**
@ -35,9 +36,18 @@ Exception::Exception(void)
*/ */
Exception::Exception(const char *message) Exception::Exception(const char *message)
{ {
m_Message = NULL;
SetMessage(message); SetMessage(message);
} }
/**
* Destructor for the Exception class. Must be virtual for RTTI to work.
*/
Exception::~Exception(void) throw()
{
Memory::Free(m_Message);
}
/** /**
* Retrieves the description for the exception. * Retrieves the description for the exception.
* *
@ -65,9 +75,7 @@ const char *Exception::what(void) const throw()
*/ */
void Exception::SetMessage(const char *message) void Exception::SetMessage(const char *message)
{ {
if (m_Message) Memory::Free(m_Message);
delete m_Message;
m_Message = Memory::StrDup(message); m_Message = Memory::StrDup(message);
} }

View File

@ -31,7 +31,7 @@ namespace icinga
class I2_BASE_API Exception : exception class I2_BASE_API Exception : exception
{ {
private: private:
const char *m_Message; char *m_Message;
protected: protected:
void SetMessage(const char *message); void SetMessage(const char *message);
@ -39,14 +39,7 @@ protected:
public: public:
Exception(void); Exception(void);
Exception(const char *message); Exception(const char *message);
virtual ~Exception(void) throw();
/**
* Destructor for the Exception class. Must be virtual for RTTI to work.
*/
virtual ~Exception(void) throw()
{
delete m_Message;
}
const char *GetMessage(void) const; const char *GetMessage(void) const;