aboutsummaryrefslogtreecommitdiff
path: root/plugins/anydata
diff options
context:
space:
mode:
authorAleksander Morgado <aleksandermj@chromium.org>2022-08-24 12:31:47 +0000
committerAleksander Morgado <aleksandermj@chromium.org>2022-09-05 17:33:11 +0000
commit74fc5baca229922b244ad66d5819d6d765e2d9da (patch)
treeb8162255a86134a355481e4b72137d25efa39e20 /plugins/anydata
parentb2a186b5c8c5f36fe02b8fab0f64fabf2878bc21 (diff)
core: port GRegex/GMatchInfo to use autoptr()
The behavior of GRegex changed in 2.73.2 once it was ported from pcre1 to pcre2. In some cases it was made more strict, which is fine, in other cases it exposed some change in how it behaves on certain matches that is not extremely clear whether it's ok or not. See https://gitlab.gnome.org/GNOME/glib/-/issues/2729 See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/601 See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/621 Either way, one thing that was assumed was that initializing all GRegex/GMatchInfo variables to NULL and making sure they're NULL before they're initialized by glib (especially the GMatchInfo) was a good and safer approach. So, whenever possible, g_autoptr() is used to cleanup the allocated GMatchInfo/GRegex variables, and otherwise, g_clear_pointer() is used to ensure that no free/unref is attempted unless the given variable is not NULL, and also so that the variable is reseted to NULL after being disposed.
Diffstat (limited to 'plugins/anydata')
-rw-r--r--plugins/anydata/mm-broadband-modem-anydata.c82
1 files changed, 35 insertions, 47 deletions
diff --git a/plugins/anydata/mm-broadband-modem-anydata.c b/plugins/anydata/mm-broadband-modem-anydata.c
index 95f8cbd2..36d72e56 100644
--- a/plugins/anydata/mm-broadband-modem-anydata.c
+++ b/plugins/anydata/mm-broadband-modem-anydata.c
@@ -72,10 +72,10 @@ hstate_ready (MMIfaceModemCdma *self,
GTask *task)
{
DetailedRegistrationStateResults *results;
- GError *error = NULL;
- const gchar *response;
- GRegex *r;
- GMatchInfo *match_info;
+ GError *error = NULL;
+ const gchar *response;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
results = g_task_get_task_data (task);
@@ -129,9 +129,6 @@ hstate_ready (MMIfaceModemCdma *self,
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
g_task_return_pointer (task, g_memdup (results, sizeof (*results)), g_free);
g_object_unref (task);
}
@@ -142,10 +139,10 @@ state_ready (MMIfaceModemCdma *self,
GTask *task)
{
DetailedRegistrationStateResults *results;
- GError *error = NULL;
- const gchar *response;
- GRegex *r;
- GMatchInfo *match_info;
+ GError *error = NULL;
+ const gchar *response;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (error) {
@@ -194,9 +191,6 @@ state_ready (MMIfaceModemCdma *self,
}
}
- g_match_info_free (match_info);
- g_regex_unref (r);
-
/* Try for EVDO state too */
mm_base_modem_at_command (MM_BASE_MODEM (self),
"*HSTATE?",
@@ -261,9 +255,14 @@ reset (MMIfaceModem *self,
static void
setup_ports (MMBroadbandModem *self)
{
- MMPortSerialAt *ports[2];
- GRegex *regex;
- guint i;
+ MMPortSerialAt *ports[2];
+ g_autoptr(GRegex) active_regex = NULL;
+ g_autoptr(GRegex) inactive_regex = NULL;
+ g_autoptr(GRegex) dormant_regex = NULL;
+ g_autoptr(GRegex) offline_regex = NULL;
+ g_autoptr(GRegex) regreq_regex = NULL;
+ g_autoptr(GRegex) authreq_regex = NULL;
+ guint i;
/* Call parent's setup ports first always */
MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_anydata_parent_class)->setup_ports (self);
@@ -271,48 +270,37 @@ setup_ports (MMBroadbandModem *self)
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
+ /* Data call has connected */
+ active_regex = g_regex_new ("\\r\\n\\*ACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Data call disconnected */
+ inactive_regex = g_regex_new ("\\r\\n\\*INACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Modem is now dormant */
+ dormant_regex = g_regex_new ("\\r\\n\\*DORMANT:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Network acquisition fail */
+ offline_regex = g_regex_new ("\\r\\n\\*OFFLINE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Registration fail */
+ regreq_regex = g_regex_new ("\\r\\n\\*REGREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ /* Authentication fail */
+ authreq_regex = g_regex_new ("\\r\\n\\*AUTHREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+
/* Now reset the unsolicited messages */
for (i = 0; i < G_N_ELEMENTS (ports); i++) {
if (!ports[i])
continue;
/* Data state notifications */
-
- /* Data call has connected */
- regex = g_regex_new ("\\r\\n\\*ACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
-
- /* Data call disconnected */
- regex = g_regex_new ("\\r\\n\\*INACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
-
- /* Modem is now dormant */
- regex = g_regex_new ("\\r\\n\\*DORMANT:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), active_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), inactive_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), dormant_regex, NULL, NULL, NULL);
/* Abnormal state notifications
*
* FIXME: set 1X/EVDO registration state to UNKNOWN when these
* notifications are received?
*/
-
- /* Network acquisition fail */
- regex = g_regex_new ("\\r\\n\\*OFFLINE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
-
- /* Registration fail */
- regex = g_regex_new ("\\r\\n\\*REGREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
-
- /* Authentication fail */
- regex = g_regex_new ("\\r\\n\\*AUTHREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
- mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regex, NULL, NULL, NULL);
- g_regex_unref (regex);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), offline_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), regreq_regex, NULL, NULL, NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (MM_PORT_SERIAL_AT (ports[i]), authreq_regex, NULL, NULL, NULL);
}
}