From 9dc4524b79e24991936887c235c49c61377f508d Mon Sep 17 00:00:00 2001 From: gichan Date: Tue, 20 Dec 2022 16:53:59 +0900 Subject: [PATCH] [TEST/coverity] Check return value Fix coverity issue. - Check return value of `g_remove`. Signed-off-by: gichan --- tests/common/unittest_common.cc | 3 +- tests/cpp_methods/unittest_cpp_methods.cc | 40 +++++++++--------------- tests/nnstreamer_converter/unittest_converter.cc | 9 ++---- tests/nnstreamer_decoder/unittest_decoder.cc | 6 ++-- tests/nnstreamer_if/unittest_if.cc | 18 ++++------- tests/nnstreamer_sink/unittest_sink.cc | 7 +---- tests/unittest_util.c | 14 +++++++++ tests/unittest_util.h | 5 +++ 8 files changed, 46 insertions(+), 56 deletions(-) diff --git a/tests/common/unittest_common.cc b/tests/common/unittest_common.cc index 8654268..d54aac3 100644 --- a/tests/common/unittest_common.cc +++ b/tests/common/unittest_common.cc @@ -1685,9 +1685,8 @@ TEST (confCustom, checkExtraConfPath_p) EXPECT_TRUE (nnsconf_loadconf (TRUE)); EXPECT_TRUE (check_custom_conf ("common", "extra_config_path", extra_conf)); - g_remove (filename); + removeTempFile (&filename); g_free (fullpath); - g_free (filename); if (confenv) { EXPECT_TRUE (g_setenv ("NNSTREAMER_CONF", confenv, TRUE)); diff --git a/tests/cpp_methods/unittest_cpp_methods.cc b/tests/cpp_methods/unittest_cpp_methods.cc index ec81b53..57b780e 100644 --- a/tests/cpp_methods/unittest_cpp_methods.cc +++ b/tests/cpp_methods/unittest_cpp_methods.cc @@ -120,10 +120,9 @@ TEST (cppFilterOnDemand, pipeline01) } g_free (str_pipeline); - g_remove (tmp1); - g_remove (tmp2); - g_free (tmp1); - g_free (tmp2); + removeTempFile (&tmp1); + removeTempFile (&tmp2); + EXPECT_EQ (basic._unregister (), 0); } @@ -199,12 +198,9 @@ TEST (cppFilterObj, base01_n) } g_free (str_pipeline); - g_remove (tmp1); - g_remove (tmp2); - g_remove (tmp3); - g_free (tmp1); - g_free (tmp2); - g_free (tmp3); + removeTempFile (&tmp1); + removeTempFile (&tmp2); + removeTempFile (&tmp3); } /** @brief gtest method */ @@ -245,12 +241,9 @@ TEST (cppFilterObj, base02_n) } g_free (str_pipeline); - g_remove (tmp1); - g_remove (tmp2); - g_remove (tmp3); - g_free (tmp1); - g_free (tmp2); - g_free (tmp3); + removeTempFile (&tmp1); + removeTempFile (&tmp2); + removeTempFile (&tmp3); } /** @brief gtest method */ @@ -310,16 +303,11 @@ TEST (cppFilterObj, base03) } g_free (str_pipeline); - g_remove (tmp1); - g_remove (tmp2); - g_remove (tmp3); - g_remove (tmp4); - g_remove (tmp5); - g_free (tmp1); - g_free (tmp2); - g_free (tmp3); - g_free (tmp4); - g_free (tmp5); + removeTempFile (&tmp1); + removeTempFile (&tmp2); + removeTempFile (&tmp3); + removeTempFile (&tmp4); + removeTempFile (&tmp5); } /** diff --git a/tests/nnstreamer_converter/unittest_converter.cc b/tests/nnstreamer_converter/unittest_converter.cc index 965a99f..fd48014 100644 --- a/tests/nnstreamer_converter/unittest_converter.cc +++ b/tests/nnstreamer_converter/unittest_converter.cc @@ -152,12 +152,9 @@ TEST (tensorConverterCustom, normal0) gst_object_unref (pipeline); g_free (str_pipeline); - g_remove (tmp_tensor_raw); - g_remove (tmp_flex_raw); - g_remove (tmp_flex_to_tensor); - g_free (tmp_tensor_raw); - g_free (tmp_flex_raw); - g_free (tmp_flex_to_tensor); + removeTempFile (&tmp_tensor_raw); + removeTempFile (&tmp_flex_raw); + removeTempFile (&tmp_flex_to_tensor); g_free (received); } diff --git a/tests/nnstreamer_decoder/unittest_decoder.cc b/tests/nnstreamer_decoder/unittest_decoder.cc index 42bfdf8..0cb1255 100644 --- a/tests/nnstreamer_decoder/unittest_decoder.cc +++ b/tests/nnstreamer_decoder/unittest_decoder.cc @@ -141,10 +141,8 @@ TEST (tensorDecoderCustom, normal0) gst_object_unref (pipeline); g_free (str_pipeline); - g_remove (tmp_flex_default); - g_remove (tmp_flex_custom); - g_free (tmp_flex_default); - g_free (tmp_flex_custom); + removeTempFile (&tmp_flex_default); + removeTempFile (&tmp_flex_custom); } /** diff --git a/tests/nnstreamer_if/unittest_if.cc b/tests/nnstreamer_if/unittest_if.cc index 19c3140..32a4320 100644 --- a/tests/nnstreamer_if/unittest_if.cc +++ b/tests/nnstreamer_if/unittest_if.cc @@ -347,8 +347,7 @@ TEST_F (tensor_if_run, action_0) gst_object_unref (pipeline); g_free (str_pipeline); - g_remove (tmp); - g_free (tmp); + removeTempFile (&tmp); } /** @@ -409,10 +408,8 @@ TEST_F (tensor_if_run, action_1) g_free (str_pipeline); - g_remove (tmp_true); - g_remove (tmp_false); - g_free (tmp_true); - g_free (tmp_false); + removeTempFile (&tmp_true); + removeTempFile (&tmp_false); } #define change_transform_type(type, size) \ @@ -477,10 +474,8 @@ TEST_F (tensor_if_run, action_2) gst_object_unref (pipeline); g_free (str_pipeline); - g_remove (tmp1); - g_remove (tmp2); - g_free (tmp1); - g_free (tmp2); + removeTempFile (&tmp1); + removeTempFile (&tmp2); } /** @@ -534,8 +529,7 @@ TEST_F (tensor_if_run, action_3) gst_object_unref (pipeline); g_free (str_pipeline); - g_remove (tmp); - g_free (tmp); + removeTempFile (&tmp); } /** diff --git a/tests/nnstreamer_sink/unittest_sink.cc b/tests/nnstreamer_sink/unittest_sink.cc index f37c957..4e5fa91 100644 --- a/tests/nnstreamer_sink/unittest_sink.cc +++ b/tests/nnstreamer_sink/unittest_sink.cc @@ -216,12 +216,7 @@ _free_test_data (TestOption &option) g_free (g_test_data.caps_name); /** remove temp file */ - if (option.tmpfile) { - if (g_remove (option.tmpfile) != 0) { - _print_log ("failed to remove temp file %s", option.tmpfile); - } - g_free (option.tmpfile); - } + removeTempFile (&option.tmpfile); gst_tensors_config_free (&g_test_data.tensors_config); } diff --git a/tests/unittest_util.c b/tests/unittest_util.c index 689305e..005304e 100644 --- a/tests/unittest_util.c +++ b/tests/unittest_util.c @@ -71,6 +71,20 @@ getTempFilename (void) } /** + * @brief Remove temp file and release file name. + */ +void removeTempFile (char **file_name) +{ + if (*file_name) { + if (g_remove (*file_name) != 0) { + _print_log ("failed to remove temp file %s", *file_name); + } + g_free (*file_name); + *file_name = NULL; + } +} + +/** * @brief Wait until the pipeline processing the buffers * @return TRUE on success, FALSE when a time-out occurs */ diff --git a/tests/unittest_util.h b/tests/unittest_util.h index de798b6..d504d42 100644 --- a/tests/unittest_util.h +++ b/tests/unittest_util.h @@ -45,6 +45,11 @@ extern int setPipelineStateSync (GstElement *pipeline, GstState state, uint32_t extern gchar * getTempFilename (void); /** + * @brief Remove temp file and release file name. + */ +extern void removeTempFile (char **file_name); + +/** * @brief Wait until the pipeline processing the buffers * @return TRUE on success, FALSE when a time-out occurs */ -- 2.7.4