From 93b9012f3cf2a48a7e0ccbf961b58bd45ff5e36d Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Mon, 13 Sep 2021 17:31:31 +0900 Subject: [PATCH] [Svace] fix res leak case Fix svace issue, - fix invalid condition to check the args. - possible res leak in query close function. - condition to free strings for test models. Signed-off-by: Jaeyun --- gst/nnstreamer/tensor_if/gsttensorif.c | 14 +++----- gst/nnstreamer/tensor_query/tensor_query_common.c | 11 +++--- .../unittest_tizen_nnfw_runtime_raw.cc | 41 ++++++++++------------ 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/gst/nnstreamer/tensor_if/gsttensorif.c b/gst/nnstreamer/tensor_if/gsttensorif.c index f49dd10..0956f53 100644 --- a/gst/nnstreamer/tensor_if/gsttensorif.c +++ b/gst/nnstreamer/tensor_if/gsttensorif.c @@ -354,19 +354,15 @@ gst_tensor_if_set_property_supplied_value (const GValue * value, { gint i; gboolean is_float = FALSE; - const gchar *param; - gchar **strv; - gint num; + const gchar *param = g_value_get_string (value); + gchar **strv = g_strsplit_set (param, delimiters, -1); + gint num = g_strv_length (strv); - if (!value) { - ml_loge ("Invalid supplied value. The value is NULL"); + if (!param) { + ml_loge ("Invalid supplied value. The value is NULL."); return; } - param = g_value_get_string (value); - strv = g_strsplit_set (param, delimiters, -1); - num = g_strv_length (strv); - if (strchr (param, '.') || strchr (param, 'E') || strchr (param, 'e')) { is_float = TRUE; } diff --git a/gst/nnstreamer/tensor_query/tensor_query_common.c b/gst/nnstreamer/tensor_query/tensor_query_common.c index 8297f63..45ec566 100644 --- a/gst/nnstreamer/tensor_query/tensor_query_common.c +++ b/gst/nnstreamer/tensor_query/tensor_query_common.c @@ -368,6 +368,8 @@ int nnstreamer_query_close (query_connection_handle connection) { TensorQueryConnection *conn = (TensorQueryConnection *) connection; + int ret = 0; + if (!conn) { nns_loge ("Invalid connection data"); return -EINVAL; @@ -379,19 +381,20 @@ nnstreamer_query_close (query_connection_handle connection) if (!g_socket_close (conn->socket, &err)) { nns_loge ("Failed to close socket: %s", err->message); g_error_free (err); - return -EREMOTEIO; } g_object_unref (conn->socket); g_object_unref (conn->cancellable); - } break; + } default: /* NYI */ - return -EPROTONOSUPPORT; + ret = -EPROTONOSUPPORT; + break; } + g_free (conn->host); g_free (conn); - return 0; + return ret; } /** diff --git a/tests/tizen_nnfw_runtime/unittest_tizen_nnfw_runtime_raw.cc b/tests/tizen_nnfw_runtime/unittest_tizen_nnfw_runtime_raw.cc index 63bc168..1778d31 100644 --- a/tests/tizen_nnfw_runtime/unittest_tizen_nnfw_runtime_raw.cc +++ b/tests/tizen_nnfw_runtime/unittest_tizen_nnfw_runtime_raw.cc @@ -295,7 +295,7 @@ get_argmax (guint8 *array, size_t size) */ TEST (nnstreamerNnfwRuntimeRawFunctions, invokeAdvanced) { - int ret; + int ret = -1; void *data = NULL; gchar *model_file, *manifest_file, *data_file; const gchar *root_path = g_getenv ("NNSTREAMER_SOURCE_ROOT_PATH"); @@ -306,9 +306,10 @@ TEST (nnstreamerNnfwRuntimeRawFunctions, invokeAdvanced) char *replace_command; gsize data_read; size_t max_idx; - gboolean status; GstTensorFilterProperties prop; + model_file = manifest_file = data_file = NULL; + /* supposed to run test in build directory */ if (root_path == NULL) root_path = ".."; @@ -316,20 +317,10 @@ TEST (nnstreamerNnfwRuntimeRawFunctions, invokeAdvanced) /** nnfw needs a directory with model file and metadata in that directory */ model_file = g_build_filename (root_path, "tests", "test_models", "models", "mobilenet_v1_1.0_224_quant.tflite", NULL); - status = g_file_test (model_file, G_FILE_TEST_EXISTS); - if (!status) { - g_free (model_file); - ASSERT_EQ (status, TRUE); - } - manifest_file = g_build_filename ( root_path, "tests", "test_models", "models", "metadata", "MANIFEST", NULL); - status = g_file_test (manifest_file, G_FILE_TEST_EXISTS); - if (!status) { - g_free (model_file); - g_free (manifest_file); - ASSERT_EQ (status, TRUE); - } + data_file = g_build_filename ( + root_path, "tests", "test_models", "data", "orange.raw", NULL); const gchar *model_files[] = { model_file, NULL, @@ -338,15 +329,19 @@ TEST (nnstreamerNnfwRuntimeRawFunctions, invokeAdvanced) const GstTensorFilterFramework *sp = nnstreamer_filter_find ("nnfw"); EXPECT_NE (sp, (void *)NULL); + if (!g_file_test (model_file, G_FILE_TEST_EXISTS) || + !g_file_test (manifest_file, G_FILE_TEST_EXISTS) || + !g_file_test (data_file, G_FILE_TEST_EXISTS)) { + goto failed; + } + replace_command = g_strdup_printf ("sed -i '/%s/c\\\"models\" : [ \"%s\" ],' %s", orig_model, new_model, manifest_file); ret = system (replace_command); g_free (replace_command); if (ret != 0) { - g_free (model_file); - g_free (manifest_file); - ASSERT_EQ (ret, 0); + goto failed; } gst_tensors_info_init (&info); @@ -398,9 +393,7 @@ TEST (nnstreamerNnfwRuntimeRawFunctions, invokeAdvanced) input.data = NULL; output.data = g_malloc (output.size); - data_file = g_build_filename ( - root_path, "tests", "test_models", "data", "orange.raw", NULL); - status = g_file_get_contents (data_file, (gchar **)&input.data, &data_read, NULL); + EXPECT_TRUE (g_file_get_contents (data_file, (gchar **)&input.data, &data_read, NULL)); EXPECT_EQ (data_read, input.size); ret = sp->invoke_NN (&prop, &data, &input, &output); @@ -412,19 +405,21 @@ TEST (nnstreamerNnfwRuntimeRawFunctions, invokeAdvanced) max_idx = get_argmax ((guint8 *)output.data, output.size); EXPECT_EQ (max_idx, 951U); - g_free (data_file); g_free (output.data); g_free (input.data); - g_free (model_file); sp->close (&prop, &data); replace_command = g_strdup_printf ("sed -i '/%s/c\\\"models\" : [ \"%s\" ],' %s", new_model, orig_model, manifest_file); ret = system (replace_command); g_free (replace_command); - g_free (manifest_file); gst_tensors_info_free (&info); gst_tensors_info_free (&res); + +failed: + g_free (model_file); + g_free (manifest_file); + g_free (data_file); ASSERT_EQ (ret, 0); } -- 2.7.4