aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-10-27 22:35:17 +0200
committerAleksander Morgado <aleksander@aleksander.es>2016-10-27 23:02:47 +0200
commitc1442b3a7fedd8b713136cd2598a210549508cdf (patch)
treec428c02495541c4e68ec8bbfc4741b94f1511229
parentb760b98a5d324351dbabb89edfeaee696ae0cf84 (diff)
libqmi-glib,device: make sure transaction is removed from table on early errors
-rw-r--r--src/libqmi-glib/qmi-device.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/libqmi-glib/qmi-device.c b/src/libqmi-glib/qmi-device.c
index cf2dfd0..c2f41c6 100644
--- a/src/libqmi-glib/qmi-device.c
+++ b/src/libqmi-glib/qmi-device.c
@@ -2754,6 +2754,23 @@ qmi_device_command_finish (QmiDevice *self,
G_SIMPLE_ASYNC_RESULT (res)));
}
+static void
+transaction_early_error (QmiDevice *self,
+ Transaction *tr,
+ gboolean stored,
+ GError *error)
+{
+ g_assert (error);
+
+ if (stored) {
+ /* Match transaction so that we remove it from our tracking table */
+ tr = device_match_transaction (self, tr->message);
+ g_assert (tr);
+ }
+ transaction_complete_and_free (tr, NULL, error);
+ g_error_free (error);
+}
+
/**
* qmi_device_command:
* @self: a #QmiDevice.
@@ -2807,8 +2824,7 @@ qmi_device_command (QmiDevice *self,
error = g_error_new (QMI_CORE_ERROR,
QMI_CORE_ERROR_WRONG_STATE,
"Device must be open to send commands");
- transaction_complete_and_free (tr, NULL, error);
- g_error_free (error);
+ transaction_early_error (self, tr, FALSE, error);
return;
}
}
@@ -2820,8 +2836,7 @@ qmi_device_command (QmiDevice *self,
QMI_CORE_ERROR_FAILED,
"Cannot send message in service '%s' without a CID",
qmi_service_get_string (qmi_message_get_service (message)));
- transaction_complete_and_free (tr, NULL, error);
- g_error_free (error);
+ transaction_early_error (self, tr, FALSE, error);
return;
}
@@ -2829,8 +2844,7 @@ qmi_device_command (QmiDevice *self,
* (only applicable if we did version info check when opening) */
if (!check_message_supported (self, message, &error)) {
g_prefix_error (&error, "Cannot send message: ");
- transaction_complete_and_free (tr, NULL, error);
- g_error_free (error);
+ transaction_early_error (self, tr, FALSE, error);
return;
}
@@ -2838,8 +2852,7 @@ qmi_device_command (QmiDevice *self,
raw_message = qmi_message_get_raw (message, &raw_message_len, &error);
if (!raw_message) {
g_prefix_error (&error, "Cannot get raw message: ");
- transaction_complete_and_free (tr, NULL, error);
- g_error_free (error);
+ transaction_early_error (self, tr, FALSE, error);
return;
}
@@ -2854,11 +2867,13 @@ qmi_device_command (QmiDevice *self,
/* Setup context to match response */
if (!device_store_transaction (self, tr, transaction_timeout, &error)) {
g_prefix_error (&error, "Cannot store transaction: ");
- transaction_complete_and_free (tr, NULL, error);
- g_error_free (error);
+ transaction_early_error (self, tr, FALSE, error);
return;
}
+ /* From now on, if we want to complete the transaction with an early error,
+ * it needs to be removed from the tracking table as well. */
+
if (qmi_utils_get_traces_enabled ()) {
gchar *printable;
@@ -2891,8 +2906,7 @@ qmi_device_command (QmiDevice *self,
cancellable,
&error)) {
g_prefix_error (&error, "Cannot create MBIM command: ");
- transaction_complete_and_free (tr, NULL, error);
- g_error_free (error);
+ transaction_early_error (self, tr, TRUE, error);
}
return;
}
@@ -2905,10 +2919,8 @@ qmi_device_command (QmiDevice *self,
NULL, /* cancellable */
&error)) {
g_prefix_error (&error, "Cannot write message: ");
- /* Match transaction so that we remove it from our tracking table */
- tr = device_match_transaction (self, message);
- transaction_complete_and_free (tr, NULL, error);
- g_error_free (error);
+ transaction_early_error (self, tr, TRUE, error);
+ return;
}
/* Flush explicitly if correctly written */