From 055836dffdf57df020b13238b66425f9cc2533c1 Mon Sep 17 00:00:00 2001 From: Jaeyun Jung Date: Fri, 21 Aug 2026 16:01:28 +0900 Subject: [PATCH] [C-Api] release allocated data Release allocated memory when ml-tensors-data handle is destroyed. Signed-off-by: Jaeyun Jung --- c/src/ml-api-common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/c/src/ml-api-common.c b/c/src/ml-api-common.c index 347fe7ef..c129fb4c 100644 --- a/c/src/ml-api-common.c +++ b/c/src/ml-api-common.c @@ -712,7 +712,7 @@ _ml_tensors_data_destroy_internal (ml_tensors_data_h data, gboolean free_data) status); } } else { - for (i = 0; i < ML_TENSOR_SIZE_LIMIT; i++) { + for (i = 0; i < _data->num_tensors; i++) { g_clear_pointer (&_data->tensors[i].data, g_free); } } @@ -772,6 +772,11 @@ _ml_tensors_data_create_no_alloc (const ml_tensors_info_h info, g_mutex_init (&_data->lock); + /** + * We now release allocated data only when _ml_tensors_data_destroy_internal() is called. + * Be careful, if you update the number of tensors after creating the data handle, + * you should manage the memories with changed index. + */ _info = (ml_tensors_info_s *) info; if (_info != NULL) { status = _ml_tensors_info_create_from (info, &_data->info);