[Coverity] fix coverity issue
authorJaeyun <jy1210.jung@samsung.com>
Mon, 2 Mar 2020 04:43:25 +0000 (13:43 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 2 Mar 2020 11:25:11 +0000 (20:25 +0900)
1. init null before getting the file contents.
2. fix mem leak

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
tests/nnstreamer_filter_armnn/unittest_filter_armnn.cc
tests/nnstreamer_sink/unittest_sink.cc
tests/tizen_capi/unittest_tizen_capi.cc
tests/tizen_nnfw_runtime/unittest_tizen_nnfw_runtime_raw.cc

index 0f62b8e..df30a50 100644 (file)
@@ -362,7 +362,9 @@ TEST (nnstreamer_filter_armnn, invoke_01)
   void *data = NULL;
   gchar *model_file, *data_file;
   const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH");
-  GstTensorMemory input_uint8, output, input;
+  gchar *input_uint8_data = NULL;
+  gsize input_uint8_size = 0;
+  GstTensorMemory output, input;
   ssize_t max_idx;
   const unsigned int num_labels = 10;
 
@@ -394,16 +396,16 @@ TEST (nnstreamer_filter_armnn, invoke_01)
   prop.input_meta.num_tensors = 1;
   prop.input_meta.info[0].name = g_strdup ("data");
 
-  EXPECT_TRUE (g_file_get_contents (data_file, (gchar **) &input_uint8.data,
-        &input_uint8.size, NULL));
+  EXPECT_TRUE (g_file_get_contents (data_file, &input_uint8_data,
+        &input_uint8_size, NULL));
 
   /** Convert the data from uint8 to float */
   input.type = _NNS_FLOAT32;
-  input.size = input_uint8.size * gst_tensor_get_element_size (input.type);
+  input.size = input_uint8_size * gst_tensor_get_element_size (input.type);
   input.data = g_malloc (input.size);
-  for (unsigned int idx=0; idx < input_uint8.size; idx ++) {
+  for (gsize idx=0; idx < input_uint8_size; idx ++) {
     ((float *) input.data)[idx] =
-      static_cast<float> (((guint8 *) input_uint8.data)[idx]);
+      static_cast<float> (((guint8 *) input_uint8_data)[idx]);
     ((float *) input.data)[idx] -= 127.5;
     ((float *) input.data)[idx] /= 127.5;
   }
@@ -456,7 +458,7 @@ TEST (nnstreamer_filter_armnn, invoke_01)
 
   g_free (data_file);
   g_free (input.data);
-  g_free (input_uint8.data);
+  g_free (input_uint8_data);
   g_free (output.data);
   g_free (prop.output_meta.info[0].name);
   g_free (prop.input_meta.info[0].name);
@@ -481,6 +483,6 @@ main (int argc, char **argv)
   } catch (...) {
     g_warning ("catch `testing::internal::GoogleTestFailureException`");
   }
-  
+
   return result;
 }
index 79c86a5..19fca68 100644 (file)
@@ -4466,7 +4466,7 @@ TEST (tensor_stream_test, issue739_mux_parallel_1)
 
   /** @todo Check contents in the sink */
   if (option.tmpfile) {
-    gchar *data;
+    gchar *data = NULL;
     gsize read, i;
 
     if (g_file_get_contents (option.tmpfile, &data, &read, NULL)) {
@@ -4531,7 +4531,7 @@ TEST (tensor_stream_test, issue739_mux_parallel_2)
 
   /** @todo Check contents in the sink */
   if (option.tmpfile) {
-    gchar *data;
+    gchar *data = NULL;
     gsize read, i;
 
     if (g_file_get_contents (option.tmpfile, &data, &read, NULL)) {
@@ -4597,7 +4597,7 @@ TEST (tensor_stream_test, issue739_mux_parallel_3)
 
   /** @todo Check contents in the sink */
   if (option.tmpfile) {
-    gchar *data;
+    gchar *data = NULL;
     gsize read, i;
     uint32_t lastval;
 
@@ -4680,7 +4680,7 @@ TEST (tensor_stream_test, issue739_merge_parallel_1)
 
   /** @todo Check contents in the sink */
   if (option.tmpfile) {
-    gchar *data;
+    gchar *data = NULL;
     gsize read, i;
 
     if (g_file_get_contents (option.tmpfile, &data, &read, NULL)) {
@@ -4745,7 +4745,7 @@ TEST (tensor_stream_test, issue739_merge_parallel_2)
 
   /** @todo Check contents in the sink */
   if (option.tmpfile) {
-    gchar *data;
+    gchar *data = NULL;
     gsize read, i;
 
     if (g_file_get_contents (option.tmpfile, &data, &read, NULL)) {
@@ -4811,7 +4811,7 @@ TEST (tensor_stream_test, issue739_merge_parallel_3)
 
   /** @todo Check contents in the sink */
   if (option.tmpfile) {
-    gchar *data;
+    gchar *data = NULL;
     gsize read, i;
     uint32_t lastval;
 
index 740b26b..5650392 100644 (file)
@@ -462,7 +462,8 @@ static int
 file_cmp (const gchar * f1, const gchar * f2)
 {
   gboolean r;
-  gchar *content1, *content2;
+  gchar *content1 = NULL;
+  gchar *content2 = NULL;
   gsize len1, len2;
   int cmp = 0;
 
@@ -768,7 +769,7 @@ TEST (nnstreamer_capi_src, dummy_01)
   int i;
   uint8_t *uintarray1[10];
   uint8_t *uintarray2[10];
-  uint8_t *content;
+  uint8_t *content = NULL;
   gsize len;
 
   status = ml_pipeline_construct (pipeline, NULL, NULL, &handle);
@@ -4100,7 +4101,7 @@ main (int argc, char **argv)
   } catch (...) {
     g_warning ("catch `testing::internal::GoogleTestFailureException`");
   }
-  
+
   set_feature_state (-1);
 
   return result;
index a3ae761..c7531a9 100644 (file)
@@ -396,7 +396,7 @@ TEST (nnstreamer_nnfw_runtime_raw_functions, DISABLED_invoke_advanced)
   output.type = res.info[0].type;
   output.size = gst_tensor_info_get_size (&res.info[0]);
 
-  input.data = g_malloc (input.size);
+  input.data = NULL;
   output.data = g_malloc (output.size);
 
   data_file = g_build_filename (root_path, "tests", "test_models", "data",