From 9e653807f906bb3b2e178d8a452d4dd0700b13fa Mon Sep 17 00:00:00 2001 From: hyunil park Date: Mon, 28 Aug 2023 12:06:46 +0900 Subject: [PATCH] [C-API] Bugfix for ml_pipeline_element_get_handle Need to ref element obtained by iterate_element() and unref it in cleanup_node() for common_elem - common_elem by ml_pipeline_element_get_handle() need to unref in cleaunup_node() because g_hash_table_lookup assign new memory. but normal operation, unref is not necessary, so add ref in iterate_element() - Now, the element's finalize function is called after ml_pipeline_element_get_handle() Signed-off-by: hyunil park --- c/src/ml-api-inference-pipeline.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/c/src/ml-api-inference-pipeline.c b/c/src/ml-api-inference-pipeline.c index 5e1fa0d..d513f59 100644 --- a/c/src/ml-api-inference-pipeline.c +++ b/c/src/ml-api-inference-pipeline.c @@ -601,6 +601,8 @@ cleanup_node (gpointer data) if (e->sink) gst_object_unref (e->sink); + gst_object_unref (e->element); + _ml_tensors_info_free (&e->tensors_info); g_mutex_unlock (&e->lock); @@ -915,7 +917,8 @@ iterate_element (ml_pipeline * pipe_h, GstElement * pipeline, if (element_type != ML_PIPELINE_ELEMENT_UNKNOWN) { ml_pipeline_element *e; - e = construct_element (elem, pipe_h, name, element_type); + e = construct_element (gst_object_ref (elem), pipe_h, name, + element_type); if (e != NULL) { if (g_str_equal (element_name, "tensor_if")) process_tensor_if_option (e); @@ -925,6 +928,7 @@ iterate_element (ml_pipeline * pipe_h, GstElement * pipeline, g_hash_table_insert (pipe_h->namednodes, g_strdup (name), e); } else { /* allocation failure */ + gst_object_unref (elem); _ml_error_report_continue ("Cannot allocate memory with construct_element()."); status = ML_ERROR_OUT_OF_MEMORY; -- 2.7.4