aboutsummaryrefslogtreecommitdiff
path: root/src/mm-port-serial-at.c
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 /src/mm-port-serial-at.c
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 'src/mm-port-serial-at.c')
-rw-r--r--src/mm-port-serial-at.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/mm-port-serial-at.c b/src/mm-port-serial-at.c
index 44c0fc92..88d01cf4 100644
--- a/src/mm-port-serial-at.c
+++ b/src/mm-port-serial-at.c
@@ -269,8 +269,8 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response)
for (iter = self->priv->unsolicited_msg_handlers; iter; iter = iter->next) {
MMAtUnsolicitedMsgHandler *handler = (MMAtUnsolicitedMsgHandler *) iter->data;
- GMatchInfo *match_info;
- gboolean matches;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gboolean matches;
if (!handler->enable)
continue;
@@ -286,12 +286,10 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response)
}
}
- g_match_info_free (match_info);
-
if (matches) {
/* Remove matches */
- char *str;
- int result_len = response->len;
+ g_autofree gchar *str = NULL;
+ gint result_len = response->len;
str = g_regex_replace_eval (handler->regex,
(const char *) response->data,
@@ -301,7 +299,6 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response)
g_byte_array_remove_range (response, 0, response->len);
g_byte_array_append (response, (const guint8 *) str, result_len);
- g_free (str);
}
}
}