From: Jaeyun Date: Thu, 21 Jul 2022 02:09:36 +0000 (+0900) Subject: [Svace] code clean and fix svace X-Git-Tag: accepted/tizen/unified/20220811.135951~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ef2db4ce6f810a977cfa04df9f61b3e61e53685;p=platform%2Fupstream%2Fnnstreamer.git [Svace] code clean and fix svace Code clean, fix svace issues. - check null string when getting caps from edge handle - fix mem leak case - fix invalid data comparison Signed-off-by: Jaeyun --- diff --git a/gst/nnstreamer/elements/gsttensor_merge.c b/gst/nnstreamer/elements/gsttensor_merge.c index bd6a007..419a9b3 100644 --- a/gst/nnstreamer/elements/gsttensor_merge.c +++ b/gst/nnstreamer/elements/gsttensor_merge.c @@ -783,10 +783,14 @@ gst_tensor_merge_set_option_data (GstTensorMerge * tensor_merge) switch (tensor_merge->mode) { case GTT_LINEAR: { - tensor_merge->data_linear.direction = + gint idx; + + idx = find_key_strv (gst_tensor_merge_linear_string, tensor_merge->option); - if (tensor_merge->data_linear.direction < 0) + if (idx < 0) return FALSE; + + tensor_merge->data_linear.direction = (tensor_merge_linear_mode) idx; tensor_merge->loaded = TRUE; } break; diff --git a/gst/nnstreamer/tensor_query/tensor_query_client.c b/gst/nnstreamer/tensor_query/tensor_query_client.c index e5024d1..ebf7110 100644 --- a/gst/nnstreamer/tensor_query/tensor_query_client.c +++ b/gst/nnstreamer/tensor_query/tensor_query_client.c @@ -561,6 +561,8 @@ gst_tensor_query_client_sink_event (GstPad * pad, g_free (self->in_caps_str); self->in_caps_str = gst_caps_to_string (caps); nns_edge_get_info (self->edge_h, "CAPS", &prev_caps_str); + if (!prev_caps_str) + prev_caps_str = g_strdup (""); new_caps_str = g_strconcat (prev_caps_str, self->in_caps_str, NULL); nns_edge_set_info (self->edge_h, "CAPS", new_caps_str); g_free (prev_caps_str); @@ -688,12 +690,14 @@ gst_tensor_query_client_chain (GstPad * pad, data_h = g_async_queue_try_pop (self->msg_queue); if (data_h) { - out_buf = gst_buffer_new (); - if (NNS_EDGE_ERROR_NONE != nns_edge_data_get_count (data_h, &num_data)) { + ret = nns_edge_data_get_count (data_h, &num_data); + if (ret != NNS_EDGE_ERROR_NONE || num_data == 0) { nns_loge ("Failed to get the number of memories of the edge data."); res = GST_FLOW_ERROR; goto done; } + + out_buf = gst_buffer_new (); for (i = 0; i < num_data; i++) { void *data = NULL; size_t data_len; diff --git a/gst/nnstreamer/tensor_query/tensor_query_server.c b/gst/nnstreamer/tensor_query/tensor_query_server.c index 2d55bcd..df2fd4a 100644 --- a/gst/nnstreamer/tensor_query/tensor_query_server.c +++ b/gst/nnstreamer/tensor_query/tensor_query_server.c @@ -54,6 +54,7 @@ edge_server_handle gst_tensor_query_server_add_data (char *id) { GstTensorQueryServer *data = NULL; + int ret; data = gst_tensor_query_server_get_handle (id); @@ -72,7 +73,8 @@ gst_tensor_query_server_add_data (char *id) data->id = id; data->configured = FALSE; - if (0 != nns_edge_create_handle (id, "TEMP_SERVER_TOPIC", &data->edge_h)) { + ret = nns_edge_create_handle (id, "TEMP_SERVER_TOPIC", &data->edge_h); + if (ret != NNS_EDGE_ERROR_NONE) { GST_ERROR ("Failed to get nnstreamer edge handle."); gst_tensor_query_server_remove_data (data); return NULL; diff --git a/gst/nnstreamer/tensor_query/tensor_query_serversink.c b/gst/nnstreamer/tensor_query/tensor_query_serversink.c index 7f4fd08..9c97f05 100644 --- a/gst/nnstreamer/tensor_query/tensor_query_serversink.c +++ b/gst/nnstreamer/tensor_query/tensor_query_serversink.c @@ -16,7 +16,6 @@ #include #include "tensor_query_serversink.h" -#include "nnstreamer_util.h" GST_DEBUG_CATEGORY_STATIC (gst_tensor_query_serversink_debug); #define GST_CAT_DEFAULT gst_tensor_query_serversink_debug @@ -236,6 +235,8 @@ gst_tensor_query_serversink_set_caps (GstBaseSink * bsink, GstCaps * caps) caps_str = gst_caps_to_string (caps); nns_edge_get_info (sink->edge_h, "CAPS", &prev_caps_str); + if (!prev_caps_str) + prev_caps_str = g_strdup (""); new_caps_str = g_strdup_printf ("%s@query_server_sink_caps@%s", prev_caps_str, caps_str); nns_edge_set_info (sink->edge_h, "CAPS", new_caps_str); @@ -254,7 +255,7 @@ gst_tensor_query_serversink_render (GstBaseSink * bsink, GstBuffer * buf) { GstTensorQueryServerSink *sink = GST_TENSOR_QUERY_SERVERSINK (bsink); GstMetaQuery *meta_query; - nns_edge_data_h data_h = NULL; + nns_edge_data_h data_h; guint i, num_mems = 0; gint ret; GstMemory *mem[NNS_TENSOR_SIZE_LIMIT]; @@ -277,6 +278,7 @@ gst_tensor_query_serversink_render (GstBaseSink * bsink, GstBuffer * buf) if (!gst_memory_map (mem[i], &map[i], GST_MAP_READ)) { ml_loge ("Cannot map the %uth memory in gst-buffer.", i); num_mems = i; + nns_edge_data_destroy (data_h); goto done; } nns_edge_data_add (data_h, map[i].data, map[i].size, NULL); @@ -288,7 +290,6 @@ gst_tensor_query_serversink_render (GstBaseSink * bsink, GstBuffer * buf) nns_edge_respond (sink->edge_h, data_h); nns_edge_data_destroy (data_h); - data_h = NULL; } else { nns_logw ("Cannot get tensor query meta. Drop buffers!\n"); sink->metaless_frame_count++; diff --git a/gst/nnstreamer/tensor_query/tensor_query_serversrc.c b/gst/nnstreamer/tensor_query/tensor_query_serversrc.c index da14038..ff30f6a 100644 --- a/gst/nnstreamer/tensor_query/tensor_query_serversrc.c +++ b/gst/nnstreamer/tensor_query/tensor_query_serversrc.c @@ -361,6 +361,7 @@ _gst_tensor_query_serversrc_get_buffer (GstTensorQueryServerSrc * src) GstBuffer *buffer = NULL; guint i, num_data; GstMetaQuery *meta_query; + int ret; data_h = g_async_queue_pop (src->msg_queue); @@ -368,13 +369,14 @@ _gst_tensor_query_serversrc_get_buffer (GstTensorQueryServerSrc * src) nns_loge ("Failed to get message from the server message queue"); return NULL; } - buffer = gst_buffer_new (); - if (NNS_EDGE_ERROR_NONE != nns_edge_data_get_count (data_h, &num_data)) { + ret = nns_edge_data_get_count (data_h, &num_data); + if (ret != NNS_EDGE_ERROR_NONE || num_data == 0) { nns_loge ("Failed to get the number of memories of the edge data."); - gst_buffer_unref (buffer); - return NULL; + goto done; } + + buffer = gst_buffer_new (); for (i = 0; i < num_data; i++) { void *data = NULL; size_t data_len = 0; @@ -388,24 +390,22 @@ _gst_tensor_query_serversrc_get_buffer (GstTensorQueryServerSrc * src) g_free)); } - if (buffer) { - meta_query = gst_buffer_add_meta_query (buffer); - if (meta_query) { - char *val; - int ret; - - ret = nns_edge_data_get_info (data_h, "client_id", &val); - if (NNS_EDGE_ERROR_NONE != ret) { - gst_buffer_unref (buffer); - buffer = NULL; - } else { - meta_query->client_id = g_ascii_strtoll (val, NULL, 10); - g_free (val); - } + meta_query = gst_buffer_add_meta_query (buffer); + if (meta_query) { + char *val; + + ret = nns_edge_data_get_info (data_h, "client_id", &val); + if (NNS_EDGE_ERROR_NONE != ret) { + gst_buffer_unref (buffer); + buffer = NULL; + } else { + meta_query->client_id = g_ascii_strtoll (val, NULL, 10); + g_free (val); } } - nns_edge_data_destroy (data_h); +done: + nns_edge_data_destroy (data_h); return buffer; } @@ -429,6 +429,8 @@ gst_tensor_query_serversrc_create (GstPushSrc * psrc, GstBuffer ** outbuf) caps_str = gst_caps_to_string (caps); nns_edge_get_info (src->edge_h, "CAPS", &prev_caps_str); + if (!prev_caps_str) + prev_caps_str = g_strdup (""); new_caps_str = g_strdup_printf ("%s@query_server_src_caps@%s", prev_caps_str, caps_str); nns_edge_set_info (src->edge_h, "CAPS", new_caps_str); @@ -441,7 +443,7 @@ gst_tensor_query_serversrc_create (GstPushSrc * psrc, GstBuffer ** outbuf) } *outbuf = _gst_tensor_query_serversrc_get_buffer (src); - if (!outbuf) { + if (*outbuf == NULL) { nns_loge ("Failed to get buffer to push to the tensor query serversrc."); return GST_FLOW_ERROR; }