fixes memory leak in test_parser2
authorPeng Wu <alexepico@gmail.com>
Tue, 9 Oct 2012 05:58:49 +0000 (13:58 +0800)
committerPeng Wu <alexepico@gmail.com>
Tue, 9 Oct 2012 05:58:49 +0000 (13:58 +0800)
tests/storage/test_parser2.cpp

index 7c7058c..24e38c7 100644 (file)
@@ -56,6 +56,7 @@ int main(int argc, char * argv[]) {
     ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey));
     ChewingKeyRestVector key_rests =
         g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest));
+
     pinyin_option_t options = PINYIN_CORRECT_ALL | USE_TONE | USE_RESPLIT_TABLE;
 
     int i = 1;
@@ -127,8 +128,11 @@ int main(int argc, char * argv[]) {
                 &g_array_index(keys, ChewingKey, i);
             ChewingKeyRest * key_rest =
                 &g_array_index(key_rests, ChewingKeyRest, i);
-            printf("%s %d %d\t", key->get_pinyin_string(),
+
+            gchar * pinyins = key->get_pinyin_string();
+            printf("%s %d %d\t", pinyins,
                    key_rest->m_raw_begin, key_rest->m_raw_end);
+            g_free(pinyins);
         }
         printf("\n");
 #endif
@@ -138,5 +142,10 @@ int main(int argc, char * argv[]) {
     if (linebuf)
         free(linebuf);
 
+    delete parser;
+
+    g_array_free(key_rests, TRUE);
+    g_array_free(keys, TRUE);
+
     return 0;
 }