From: Peng Wu Date: Thu, 11 Oct 2012 05:47:31 +0000 (+0800) Subject: fixes memory leak in facade chewing table X-Git-Tag: 0.7.92~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d23d9fca34dae6aea0cb6e8640ccf3f2cbc81256;p=platform%2Fupstream%2Flibpinyin.git fixes memory leak in facade chewing table --- diff --git a/src/storage/facade_chewing_table.h b/src/storage/facade_chewing_table.h index da740c4..50683eb 100644 --- a/src/storage/facade_chewing_table.h +++ b/src/storage/facade_chewing_table.h @@ -39,6 +39,17 @@ private: ChewingLargeTable * m_system_chewing_table; ChewingLargeTable * m_user_chewing_table; + void reset() { + if (m_system_chewing_table) { + delete m_system_chewing_table; + m_system_chewing_table = NULL; + } + + if (m_user_chewing_table) { + delete m_user_chewing_table; + m_user_chewing_table = NULL; + } + } public: /** * FacadeChewingTable::FacadeChewingTable: @@ -52,6 +63,16 @@ public: } /** + * FacadeChewingTable::~FacadeChewingTable: + * + * The destructor of the FacadeChewingTable. + * + */ + ~FacadeChewingTable() { + reset(); + } + + /** * FacadeChewingTable::set_options: * @options: the pinyin options. * @returns: whether the setting options is successful. @@ -80,6 +101,8 @@ public: */ bool load(pinyin_option_t options, MemoryChunk * system, MemoryChunk * user){ + reset(); + bool result = false; if (system) { m_system_chewing_table = new ChewingLargeTable(options);