aboutsummaryrefslogtreecommitdiff
path: root/src/mm-serial-parsers.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-serial-parsers.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-serial-parsers.c')
-rw-r--r--src/mm-serial-parsers.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/mm-serial-parsers.c b/src/mm-serial-parsers.c
index fd01537d..a577faee 100644
--- a/src/mm-serial-parsers.c
+++ b/src/mm-serial-parsers.c
@@ -167,7 +167,7 @@ mm_serial_parser_v1_parse (gpointer data,
GError **error)
{
MMSerialParserV1 *parser = (MMSerialParserV1 *) data;
- GMatchInfo *match_info;
+ GMatchInfo *match_info = NULL;
GError *local_error = NULL;
gboolean found = FALSE;
char *str = NULL;
@@ -242,7 +242,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
}
/* Numeric CME errors */
@@ -255,7 +255,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* Numeric CMS errors */
found = g_regex_match_full (parser->regex_cms_error,
@@ -267,7 +267,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_message_error_for_code (atoi (str), log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* String CME errors */
found = g_regex_match_full (parser->regex_cme_error_str,
@@ -279,7 +279,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_string (str, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* String CMS errors */
found = g_regex_match_full (parser->regex_cms_error_str,
@@ -291,7 +291,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_message_error_for_string (str, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* Motorola EZX errors */
found = g_regex_match_full (parser->regex_ezx_error,
@@ -303,7 +303,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* Last resort; unknown error */
found = g_regex_match_full (parser->regex_unknown_error,
@@ -313,7 +313,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* Connection failures */
found = g_regex_match_full (parser->regex_connect_failed,
@@ -341,7 +341,7 @@ mm_serial_parser_v1_parse (gpointer data,
local_error = mm_connection_error_for_code (code, log_object);
goto done;
}
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
/* NA error */
found = g_regex_match_full (parser->regex_na,
@@ -357,7 +357,8 @@ mm_serial_parser_v1_parse (gpointer data,
done:
g_free (str);
- g_match_info_free (match_info);
+ g_clear_pointer (&match_info, g_match_info_free);
+
if (found)
response_clean (response);