diff options
author | Jaeyun Jung <jy1210.jung@samsung.com> | 2024-11-19 18:08:31 +0900 |
---|---|---|
committer | jaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com> | 2024-11-20 11:01:50 +0900 |
commit | 41bedd28b7576306af1c69817e35fe462de61705 (patch) | |
tree | 96b58a16de12f41d3acd9dda9f4ea540d354d8cb | |
parent | 48aed14e76de72cdeb5515a719f2f12a8c44f570 (diff) | |
download | machine-learning-tizen.tar.gz machine-learning-tizen.tar.bz2 machine-learning-tizen.zip |
[C-Api] fix mem leak caseaccepted/tizen/unified/20241120.162429tizenmainaccepted/tizen_unified
Code clean, fix mem leak case.
Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
-rw-r--r-- | c/src/ml-api-service-training-offloading.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/c/src/ml-api-service-training-offloading.c b/c/src/ml-api-service-training-offloading.c index c6e559b..13be243 100644 --- a/c/src/ml-api-service-training-offloading.c +++ b/c/src/ml-api-service-training-offloading.c @@ -199,8 +199,10 @@ _training_offloading_conf_parse_json (ml_service_s * mls, JsonObject * object) key = iter->data; if (!STR_IS_VALID (key)) { - _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, - "The parameter, 'key' is invalid. It should be a valid string."); + _ml_error_report + ("The parameter, 'key' is invalid. It should be a valid string."); + ret = ML_ERROR_INVALID_PARAMETER; + goto error; } val = _ml_service_get_json_string_member (data_obj, key); @@ -214,21 +216,28 @@ _training_offloading_conf_parse_json (ml_service_s * mls, JsonObject * object) if (!g_strstr_len (transfer_data, -1, "pipeline")) { g_free (transfer_data); - _ml_error_report_return (ML_ERROR_INVALID_PARAMETER, - "The parameter, 'val' is invalid. It should be a valid string."); + + _ml_error_report + ("The parameter, 'val' is invalid. It should be a valid string."); + ret = ML_ERROR_INVALID_PARAMETER; + goto error; } } g_hash_table_insert (training_s->transfer_data_table, g_strdup (key), transfer_data); } + +error: g_list_free (list); - /* Since we are only sending the trained model now, there is only 1 item in the list. */ - if (training_s->type == ML_TRAINING_OFFLOADING_TYPE_RECEIVER) - training_s->trained_model_path = g_strdup (transfer_data); + if (ret == ML_ERROR_NONE) { + /* Since we are only sending the trained model now, there is only 1 item in the list. */ + if (training_s->type == ML_TRAINING_OFFLOADING_TYPE_RECEIVER) + training_s->trained_model_path = g_strdup (transfer_data); + } - return ML_ERROR_NONE; + return ret; } /** @@ -849,15 +858,18 @@ _training_offloading_send_trained_model (ml_service_s * mls) } list = g_hash_table_get_keys (training_s->transfer_data_table); - if (!list) { - _ml_error_report ("Failed to get transfer data table"); - } - _ml_logd ("Send trained model"); - for (iter = list; iter != NULL; iter = g_list_next (iter)) { - _request_offloading_service (mls, iter->data, contents, len); + + if (list) { + _ml_logd ("Send trained model"); + for (iter = list; iter != NULL; iter = g_list_next (iter)) { + _request_offloading_service (mls, iter->data, contents, len); + } + + g_list_free (list); + } else { + _ml_error_report ("Failed to get transfer data table."); } - g_list_free (list); g_free (contents); return; } |