From a1029650a4c77b2652262d57c7eb1dcf641695b8 Mon Sep 17 00:00:00 2001 From: hyunil park Date: Mon, 17 Nov 2025 14:30:37 +0900 Subject: [PATCH] [single] Refactor: Improve resource cleanup logic Imporve resource cleanup logic when an error occurs in _ml_single_invoke_internal Signed-off-by: hyunil park --- c/src/ml-api-inference-single.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/c/src/ml-api-inference-single.c b/c/src/ml-api-inference-single.c index 03df6326..a4cd9d94 100644 --- a/c/src/ml-api-inference-single.c +++ b/c/src/ml-api-inference-single.c @@ -1582,23 +1582,20 @@ _ml_single_invoke_internal (ml_single_h single, single_h->invoking = TRUE; status = __invoke (single_h, _in, _out, need_alloc); ml_tensors_data_destroy (_in); + _in = NULL; single_h->invoking = FALSE; single_h->state = IDLE; - if (status != ML_ERROR_NONE) { - if (need_alloc) - ml_tensors_data_destroy (_out); - goto exit; - } - - if (need_alloc) + if (status == ML_ERROR_NONE && need_alloc) __process_output (single_h, _out); } exit: - if (status == ML_ERROR_NONE) { - if (need_alloc) + if (status == ML_ERROR_NONE && need_alloc) { *output = _out; + } else if (need_alloc) { + /* Clean up allocated output on error */ + ml_tensors_data_destroy (_out); } single_h->input = single_h->output = NULL;