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.
This commit is contained in:
@@ -54,9 +54,7 @@ static gboolean
|
||||
check_append_or_replace (MMLocationGpsNmea *self,
|
||||
const gchar *trace)
|
||||
{
|
||||
/* By default, replace */
|
||||
gboolean append_or_replace = FALSE;
|
||||
GMatchInfo *match_info = NULL;
|
||||
g_autoptr(GMatchInfo) match_info = NULL;
|
||||
|
||||
if (G_UNLIKELY (!self->priv->sequence_regex))
|
||||
self->priv->sequence_regex = g_regex_new ("\\$..(?:ALM|GSV|RTE|SFI),(\\d),(\\d).*",
|
||||
@@ -69,11 +67,11 @@ check_append_or_replace (MMLocationGpsNmea *self,
|
||||
|
||||
/* If we don't have the first element of a sequence, append */
|
||||
if (mm_get_uint_from_match_info (match_info, 2, &index) && index != 1)
|
||||
append_or_replace = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
g_match_info_free (match_info);
|
||||
|
||||
return append_or_replace;
|
||||
/* By default, replace */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@@ -190,7 +190,7 @@ gboolean
|
||||
mm_location_gps_raw_add_trace (MMLocationGpsRaw *self,
|
||||
const gchar *trace)
|
||||
{
|
||||
GMatchInfo *match_info = NULL;
|
||||
g_autoptr(GMatchInfo) match_info = NULL;
|
||||
|
||||
/* Current implementation works only with $GPGGA and $GNGGA traces */
|
||||
do {
|
||||
@@ -268,8 +268,6 @@ mm_location_gps_raw_add_trace (MMLocationGpsRaw *self,
|
||||
mm_get_double_from_match_info (match_info, 9, &self->priv->altitude);
|
||||
}
|
||||
|
||||
g_match_info_free (match_info);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user