diff options
author | Aleksander Morgado <aleksandermj@chromium.org> | 2024-03-07 09:11:39 +0000 |
---|---|---|
committer | Aleksander Morgado <aleksandermj@chromium.org> | 2024-03-12 10:15:59 +0000 |
commit | aec461132ce42bc430c8810e43016b858d5df890 (patch) | |
tree | f43f31dc6c58e08e9ed5df28cb441177b48ea2dc /src/mm-base-modem-at.c | |
parent | f90778df437d4dbc63bf6415e11b0bbf783efdf5 (diff) |
base-modem-at: switch command error handling to g_autoptr
Diffstat (limited to 'src/mm-base-modem-at.c')
-rw-r--r-- | src/mm-base-modem-at.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/mm-base-modem-at.c b/src/mm-base-modem-at.c index cc2bc5a0..6586f855 100644 --- a/src/mm-base-modem-at.c +++ b/src/mm-base-modem-at.c @@ -182,9 +182,9 @@ at_sequence_parse_response (MMPortSerialAt *port, GError *result_error = NULL; AtSequenceContext *ctx; g_autofree gchar *response = NULL; - GError *error = NULL; + g_autoptr(GError) command_error = NULL; - response = mm_port_serial_at_command_finish (port, res, &error); + response = mm_port_serial_at_command_finish (port, res, &command_error); /* Cancelled? */ if (g_task_return_error_if_cancelled (task)) { @@ -204,7 +204,7 @@ at_sequence_parse_response (MMPortSerialAt *port, ctx->current->command, response, next->command ? FALSE : TRUE, /* Last command in sequence? */ - error, + command_error, &result, &result_error); switch (processor_result) { @@ -219,17 +219,12 @@ at_sequence_parse_response (MMPortSerialAt *port, g_assert (!result && result_error); /* result is optional */ g_task_return_error (task, result_error); g_object_unref (task); - if (error) - g_error_free (error); return; default: g_assert_not_reached (); } } - if (error) - g_error_free (error); - if (processor_result == MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE) { ctx->current++; if (ctx->current->command) { @@ -526,29 +521,29 @@ at_command_ready (MMPortSerialAt *port, GAsyncResult *res, GTask *task) { - AtCommandContext *ctx; - GError *error = NULL; + AtCommandContext *ctx; + g_autoptr(GError) command_error = NULL; ctx = g_task_get_task_data (task); g_assert (!ctx->response); - ctx->response = mm_port_serial_at_command_finish (port, res, &error); + ctx->response = mm_port_serial_at_command_finish (port, res, &command_error); /* Cancelled? */ if (g_task_return_error_if_cancelled (task)) { - if (error) - g_error_free (error); + g_object_unref (task); + return; } + /* Error coming from the serial port? */ - else if (error) - g_task_return_error (task, error); + if (command_error) + g_task_return_error (task, g_steal_pointer (&command_error)); /* Valid string response */ else if (ctx->response) /* transfer-none, the response remains owned by the GTask context */ g_task_return_pointer (task, ctx->response, NULL); else g_assert_not_reached (); - g_object_unref (task); } |