[WIP] DataRepo Memory Leak Fix
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 28 Aug 2023 10:03:05 +0000 (19:03 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 31 Aug 2023 05:02:34 +0000 (14:02 +0900)
There are a few more leaks to be fixed.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
gst/datarepo/gstdatareposink.c
tests/nnstreamer_datarepo/unittest_datareposink.cc
tests/nnstreamer_datarepo/unittest_datareposrc.cc

index 3121c96..df21163 100644 (file)
@@ -209,6 +209,16 @@ gst_data_repo_sink_finalize (GObject * object)
   if (sink->fixed_caps)
     gst_caps_unref (sink->fixed_caps);
 
+  if (sink->sample_offset_array)
+    json_array_unref (sink->sample_offset_array);
+  if (sink->tensor_size_array)
+    json_array_unref (sink->tensor_size_array);
+  if (sink->tensor_count_array)
+    json_array_unref (sink->tensor_count_array);
+  if (sink->json_object) {
+    json_object_unref (sink->json_object);
+    sink->json_object = NULL;
+  }
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -733,6 +743,10 @@ gst_data_repo_sink_write_json_meta_file (GstDataRepoSink * sink)
         sink->tensor_size_array);
     json_object_set_array_member (sink->json_object, "tensor_count",
         sink->tensor_count_array);
+
+    sink->sample_offset_array = NULL;
+    sink->tensor_size_array = NULL;
+    sink->tensor_count_array = NULL;
   } else {
     json_object_set_int_member (sink->json_object, "sample_size",
         sink->sample_size);
@@ -745,6 +759,7 @@ gst_data_repo_sink_write_json_meta_file (GstDataRepoSink * sink)
 
   json_object_unref (sink->json_object);
   g_free (caps_str);
+  sink->json_object = NULL;
 
   return ret;
 }
index bfc1024..f3bb139 100644 (file)
@@ -124,8 +124,8 @@ TEST (datareposink, writeImageFiles)
     g_free (filename);
 
     ret = g_file_load_contents (file, NULL, &contents, NULL, NULL, NULL);
-    g_object_unref (file);
     g_free (contents);
+    g_object_unref (file);
     ASSERT_EQ (ret, TRUE);
   }
 
@@ -274,9 +274,12 @@ TEST (datareposink, writeTensors)
 
   g_object_get (datareposink, "location", &get_str, NULL);
   EXPECT_STREQ (get_str, "mnist.data");
+  g_free (get_str);
 
   g_object_get (datareposink, "json", &get_str, NULL);
   EXPECT_STREQ (get_str, "mnist.json");
+  g_free (get_str);
+  gst_object_unref (datareposink);
 
   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
   ASSERT_NE (bus, nullptr);
@@ -287,8 +290,8 @@ TEST (datareposink, writeTensors)
   g_main_loop_run (loop);
 
   setPipelineStateSync (pipeline, GST_STATE_NULL, UNITTEST_STATECHANGE_TIMEOUT);
-  gst_object_unref (pipeline);
   g_main_loop_unref (loop);
+  gst_object_unref (pipeline);
 
   /* Confirm file creation */
   file = g_file_new_for_path ("mnist.data");
@@ -457,6 +460,7 @@ TEST (datareposink, invalidJsonPath0_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_object_unref (datareposink);
   gst_object_unref (pipeline);
 }
 
@@ -483,6 +487,7 @@ TEST (datareposink, invalidFilePath0_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_object_unref (datareposink);
   gst_object_unref (pipeline);
 }
 
index 467aa80..d780537 100644 (file)
@@ -97,6 +97,9 @@ create_sparse_tensors_test_file ()
   setPipelineStateSync (pipeline, GST_STATE_NULL, UNITTEST_STATECHANGE_TIMEOUT);
   gst_object_unref (pipeline);
   g_main_loop_unref (loop);
+
+  g_free (file_path);
+  g_free (json_path);
 }
 
 /**
@@ -402,6 +405,8 @@ TEST (datareposrc, invalidJsonPath0_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -428,6 +433,8 @@ TEST (datareposrc, invalidJsonPath1_n)
 
   setPipelineStateSync (pipeline, GST_STATE_NULL, UNITTEST_STATECHANGE_TIMEOUT);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -452,6 +459,8 @@ TEST (datareposrc, invalidFilePath0_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -476,6 +485,8 @@ TEST (datareposrc, invalidFilePath1_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -500,6 +511,8 @@ TEST (datareposrc, invalidCapsWithoutJSON_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -544,12 +557,15 @@ TEST (datareposrc, readTensors)
 
   g_object_get (datareposrc, "location", &get_str, NULL);
   EXPECT_STREQ (get_str, file_path);
+  g_free (get_str);
 
   g_object_get (datareposrc, "json", &get_str, NULL);
   EXPECT_STREQ (get_str, json_path);
+  g_free (get_str);
 
   g_object_get (datareposrc, "tensors-sequence", &get_str, NULL);
   EXPECT_STREQ (get_str, "0,1");
+  g_free (get_str);
 
   g_object_get (datareposrc, "is-shuffle", &get_value, NULL);
   ASSERT_EQ (get_value, 1U);
@@ -560,6 +576,7 @@ TEST (datareposrc, readTensors)
 
   EXPECT_EQ (setPipelineStateSync (pipeline, GST_STATE_NULL, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
   g_main_loop_unref (loop);
   g_free (file_path);
@@ -828,9 +845,11 @@ TEST (datareposrc, readTensorsNoJSONWithCapsParam)
 
   g_object_get (datareposrc, "location", &get_str, NULL);
   EXPECT_STREQ (get_str, file_path);
+  g_free (get_str);
 
   g_object_get (datareposrc, "tensors-sequence", &get_str, NULL);
   EXPECT_STREQ (get_str, "0,1");
+  g_free (get_str);
 
   g_object_get (datareposrc, "is-shuffle", &get_value, NULL);
   ASSERT_EQ (get_value, 1U);
@@ -841,6 +860,8 @@ TEST (datareposrc, readTensorsNoJSONWithCapsParam)
 
   EXPECT_EQ (setPipelineStateSync (pipeline, GST_STATE_NULL, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
   g_main_loop_unref (loop);
   g_free (file_path);
@@ -880,6 +901,8 @@ TEST (datareposrc, invalidStartSampleIndex0_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -918,6 +941,8 @@ TEST (datareposrc, invalidStartSampleIndex1_n)
   g_object_get (GST_OBJECT (datareposrc), "start-sample-index", &get_value, NULL);
   EXPECT_EQ (get_value, 0U);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -953,6 +978,8 @@ TEST (datareposrc, invalidStopSampleIndex0_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -991,6 +1018,8 @@ TEST (datareposrc, invalidStopSampleIndex1_n)
   g_object_get (GST_OBJECT (datareposrc), "stop-sample-index", &get_value, NULL);
   EXPECT_EQ (get_value, 0U);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -1028,6 +1057,8 @@ TEST (datareposrc, invalidEpochs0_n)
   g_object_get (GST_OBJECT (datareposrc), "epochs", &get_value, NULL);
   EXPECT_EQ (get_value, 1U);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -1063,6 +1094,8 @@ TEST (datareposrc, invalidEpochs1_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }
 
@@ -1098,6 +1131,8 @@ TEST (datareposrc, invalidTensorsSequence0_n)
   /* state chagne failure is expected */
   EXPECT_NE (setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT), 0);
 
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (datareposrc);
   gst_object_unref (pipeline);
 }