From fe571a4fb606587096a1605f2bd0597523ad3922 Mon Sep 17 00:00:00 2001 From: Sangjung Woo Date: Thu, 18 Jul 2019 19:20:51 +0900 Subject: [PATCH] [C-Api] fix memory leak bug Since developers can reduce the number of Tensors by calling ml_tensors_info_set_count(), it causes the memory leak when invoking ml_tensors_info_free() and ml_tensors_data_destroy(). This patch fixes that bug by checking all possible elements (i.e. ML_TENSOR_SIZE_LIMIT). Signed-off-by: Sangjung Woo --- api/capi/src/nnstreamer-capi-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/capi/src/nnstreamer-capi-util.c b/api/capi/src/nnstreamer-capi-util.c index 432b176..b9b47c5 100644 --- a/api/capi/src/nnstreamer-capi-util.c +++ b/api/capi/src/nnstreamer-capi-util.c @@ -397,7 +397,7 @@ ml_tensors_info_free (ml_tensors_info_s * info) if (!info) return; - for (i = 0; i < info->num_tensors; i++) { + for (i = 0; i < ML_TENSOR_SIZE_LIMIT; i++) { if (info->info[i].name) { g_free (info->info[i].name); info->info[i].name = NULL; @@ -421,7 +421,7 @@ ml_tensors_data_destroy (ml_tensors_data_h data) _data = (ml_tensors_data_s *) data; - for (i = 0; i < _data->num_tensors; i++) { + for (i = 0; i < ML_TENSOR_SIZE_LIMIT; i++) { if (_data->tensors[i].tensor) { g_free (_data->tensors[i].tensor); _data->tensors[i].tensor = NULL; -- 2.7.4