From 16dcfcfbe52e321bb92865bc53eaa247d1af6b55 Mon Sep 17 00:00:00 2001 From: Jaeyun Jung Date: Thu, 2 Nov 2023 14:12:15 +0900 Subject: [PATCH] [Common] fix mem leak case Fix mem leak case if failed to append memory into gst-buffer. Signed-off-by: Jaeyun Jung --- gst/nnstreamer/nnstreamer_plugin_api_impl.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/gst/nnstreamer/nnstreamer_plugin_api_impl.c b/gst/nnstreamer/nnstreamer_plugin_api_impl.c index 75b0816..33611af 100644 --- a/gst/nnstreamer/nnstreamer_plugin_api_impl.c +++ b/gst/nnstreamer/nnstreamer_plugin_api_impl.c @@ -346,7 +346,7 @@ gst_tensor_time_sync_buffer_from_collectpad (GstCollectPads * collect, GstTensorsConfig in_configs; GstClockTime base_time = 0; GstTensorInfo *_info; - guint i; + guint i, j; GstMemory *in_mem[NNS_TENSOR_SIZE_LIMIT + NNS_TENSOR_SIZE_EXTRA_LIMIT]; tensor_format in_formats[NNS_TENSOR_SIZE_LIMIT + NNS_TENSOR_SIZE_EXTRA_LIMIT]; @@ -494,12 +494,6 @@ gst_tensor_time_sync_buffer_from_collectpad (GstCollectPads * collect, if (gst_tensors_config_is_flexible (configs)) { /* append header if input tensor is not flexible */ - if (i >= NNS_TENSOR_SIZE_LIMIT) { - /** @todo support extra tensors in case of flexible */ - nns_loge ("The extra tensor is not supported for flexible tensor."); - return FALSE; - } - if (in_formats[i] != _NNS_TENSOR_FORMAT_FLEXIBLE) { GstTensorMetaInfo meta; @@ -510,6 +504,9 @@ gst_tensor_time_sync_buffer_from_collectpad (GstCollectPads * collect, } if (!gst_tensor_buffer_append_memory (tensors_buf, mem, _info)) { + for (j = i + 1; j < counting; j++) + gst_memory_unref (in_mem[j]); + nns_loge ("Failed to append memory to buffer."); return FALSE; } -- 2.7.4