diff options
author | Peng Wu <alexepico@gmail.com> | 2012-10-10 17:02:52 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-10-10 17:02:52 +0800 |
commit | 6a5a4a3f6eb0d951c8f0813ec806e40ace097775 (patch) | |
tree | 543ab75c7ed2c7211b1bded36f57c47d1313cb91 | |
parent | aced528d37c803442cd1f39e51e36e96c59d94f6 (diff) | |
download | libpinyin-6a5a4a3f6eb0d951c8f0813ec806e40ace097775.tar.gz libpinyin-6a5a4a3f6eb0d951c8f0813ec806e40ace097775.tar.xz libpinyin-6a5a4a3f6eb0d951c8f0813ec806e40ace097775.zip |
fixes memory leak in phrase large table2
-rw-r--r-- | src/storage/phrase_large_table2.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp index 56180d1..94edfe0 100644 --- a/src/storage/phrase_large_table2.cpp +++ b/src/storage/phrase_large_table2.cpp @@ -109,10 +109,11 @@ PhraseBitmapIndexLevel2::PhraseBitmapIndexLevel2(){ void PhraseBitmapIndexLevel2::reset(){ for ( size_t i = 0; i < PHRASE_NUMBER_OF_BITMAP_INDEX; i++){ - PhraseLengthIndexLevel2 * length_array = + PhraseLengthIndexLevel2 * & length_array = m_phrase_length_indexes[i]; if ( length_array ) delete length_array; + length_array = NULL; } } @@ -474,8 +475,11 @@ bool PhraseBitmapIndexLevel2::load(MemoryChunk * chunk, phrase_end = *index; if ( phrase_begin == phrase_end ) //null pointer continue; + + /* after reset() all phrases are null pointer. */ PhraseLengthIndexLevel2 * phrases = new PhraseLengthIndexLevel2; m_phrase_length_indexes[i] = phrases; + phrases->load(chunk, phrase_begin, phrase_end - 1); assert( phrase_end <= end ); assert( *(buf_begin + phrase_end - 1) == c_separate); @@ -524,7 +528,7 @@ bool PhraseLengthIndexLevel2::load(MemoryChunk * chunk, (buf_begin + offset + sizeof(guint32)); table_offset_t phrase_begin, phrase_end = *index; - m_phrase_array_indexes = g_array_new(FALSE, TRUE, sizeof(void *)); + g_array_set_size(m_phrase_array_indexes, 0); for (size_t i = 1; i <= nindex; ++i) { phrase_begin = phrase_end; index++; |