Fix memory leak when pos tag foreach function is not called 49/275749/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Tue, 31 May 2022 10:13:04 +0000 (19:13 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 31 May 2022 10:13:04 +0000 (19:13 +0900)
Change-Id: I95737b3ee4cc4fa32c9dcbd25b5ab9b371e93bee
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
client/nlp_client.c

index c6ef7bb354475515f30ef08979788156d04d37d9..3c69bea41bd1beb727e2752766f7084c830c8fbb 100644 (file)
@@ -86,6 +86,24 @@ static void process_pos_tag_result(nlp_h nh, bundle *msg)
 
     if (nh->pos_tag_result_cb)
         nh->pos_tag_result_cb((unsigned int)atoi(request_id), pos_tag_result_h, nh->pos_tag_result_data);
+
+    GList* iter = NULL;
+
+    if (g_list_length(glist) > 0) {
+        iter = g_list_first(glist);
+
+        while (NULL != iter) {
+            pos_tag_pair = iter->data;
+
+            /* next item */
+            iter = g_list_next(iter);
+
+            free(pos_tag_pair);
+        }
+
+        g_list_free(glist);
+        glist = NULL;
+    }
 }
 
 static void process_word_tokenize_result(nlp_h nh, bundle *msg)
@@ -412,12 +430,7 @@ int nlp_foreach_pos_tag(nlp_pos_tag_result_h pos_tag_result_h, nlp_pos_tag_forea
 
             /* next item */
             iter = g_list_next(iter);
-
-            free(pos_tag_pair);
         }
-
-        g_list_free(glist);
-        glist = NULL;
     }
 
     return NLP_ERROR_NONE;