From 0a09b53493397809fb81fc574ef9d79aa9fa2fb5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 17 Mar 2026 05:31:49 +0000 Subject: [PATCH 1/4] fix(training-offloading): free leaked pipeline buffer on cleanup path Bug: _training_offloading_services_request() allocated 'pipeline' for deferred send but did not free it in the common cleanup path. Repeated requests leaked heap memory. Fix: free pipeline together with other temporary buffers in the error/done cleanup section. Signed-off-by: Cursor Agent Co-authored-by: MyungJoo Ham --- c/src/ml-api-service-training-offloading.c | 1 + 1 file changed, 1 insertion(+) diff --git a/c/src/ml-api-service-training-offloading.c b/c/src/ml-api-service-training-offloading.c index 13722432..b6f906f6 100644 --- a/c/src/ml-api-service-training-offloading.c +++ b/c/src/ml-api-service-training-offloading.c @@ -513,6 +513,7 @@ _training_offloading_services_request (ml_service_s * mls) error: g_free (service_name); + g_free (pipeline); g_free (transfer_data); g_free (contents); g_list_free (list); From bc44e275ce4e30e752c5521bd01d43df3bab7cab Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 17 Mar 2026 05:31:49 +0000 Subject: [PATCH 2/4] fix(training-offloading): clear old receiver strings before overwrite Bug: _ml_service_training_offloading_process_received_data() overwrote receiver_pipe_json_str and trained_model_path without releasing previous allocations when multiple messages arrived. Fix: call g_clear_pointer() before assigning new duplicated/built strings. Signed-off-by: Cursor Agent Co-authored-by: MyungJoo Ham --- c/src/ml-api-service-training-offloading.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/c/src/ml-api-service-training-offloading.c b/c/src/ml-api-service-training-offloading.c index b6f906f6..a6a05883 100644 --- a/c/src/ml-api-service-training-offloading.c +++ b/c/src/ml-api-service-training-offloading.c @@ -810,6 +810,7 @@ _ml_service_training_offloading_process_received_data (ml_service_s * mls, if (training_s->type == ML_TRAINING_OFFLOADING_TYPE_RECEIVER) { if (service_type == ML_SERVICE_OFFLOADING_TYPE_PIPELINE_RAW) { + g_clear_pointer (&training_s->receiver_pipe_json_str, g_free); training_s->receiver_pipe_json_str = g_strdup (data); _ml_logd ("Received JSON string pipeline:%s", training_s->receiver_pipe_json_str); @@ -822,6 +823,7 @@ _ml_service_training_offloading_process_received_data (ml_service_s * mls, _ml_error_report_return (ret, "Failed to get name while processing the ml-offloading service."); } + g_clear_pointer (&training_s->trained_model_path, g_free); training_s->trained_model_path = g_build_path (G_DIR_SEPARATOR_S, dir_path, name, NULL); _ml_logd ("Reply: name:%s, received trained_model:%s", name, From 5b5c3fbecf59f94df212694b8ca50babcc62c343 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 17 Mar 2026 05:31:49 +0000 Subject: [PATCH 3/4] fix(training-offloading): join stale receive thread before respawn Bug: _training_offloading_check_received_data() could overwrite received_thread with a new thread handle without joining the previous one, leaking thread resources across repeated start/check cycles. Fix: join and nullify an existing thread handle before creating a new watcher thread. Signed-off-by: Cursor Agent Co-authored-by: MyungJoo Ham --- c/src/ml-api-service-training-offloading.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/c/src/ml-api-service-training-offloading.c b/c/src/ml-api-service-training-offloading.c index a6a05883..51360493 100644 --- a/c/src/ml-api-service-training-offloading.c +++ b/c/src/ml-api-service-training-offloading.c @@ -570,6 +570,11 @@ _training_offloading_check_received_data (ml_training_services_s * training_s) g_return_val_if_fail (training_s != NULL, FALSE); + if (training_s->received_thread) { + g_thread_join (training_s->received_thread); + training_s->received_thread = NULL; + } + training_s->received_thread = g_thread_new ("check_received_file", _check_received_data_thread, training_s); From 3059174d7085f3dd35165704bbbf46bb1b4a23c0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 17 Mar 2026 05:31:49 +0000 Subject: [PATCH 4/4] fix(training-offloading): free previous receiver pipeline description Bug: _ml_service_training_offloading_prepare_receiver() reassigned receiver_pipe with g_strdup() on each prepare call without freeing the previous string. Fix: clear receiver_pipe before storing the new pipeline description. Signed-off-by: Cursor Agent Co-authored-by: MyungJoo Ham --- c/src/ml-api-service-training-offloading.c | 1 + 1 file changed, 1 insertion(+) diff --git a/c/src/ml-api-service-training-offloading.c b/c/src/ml-api-service-training-offloading.c index 51360493..c8a8c1bb 100644 --- a/c/src/ml-api-service-training-offloading.c +++ b/c/src/ml-api-service-training-offloading.c @@ -715,6 +715,7 @@ _ml_service_training_offloading_prepare_receiver (ml_service_s * mls, pipe = json_object_get_object_member (pipeline_obj, "pipeline"); if (json_object_has_member (pipe, "description")) { + g_clear_pointer (&training_s->receiver_pipe, g_free); training_s->receiver_pipe = g_strdup (_ml_service_get_json_string_member (pipe, "description")); } else {