On 10/4/18 1:09 AM, Thomas Haller wrote: > --- > libmm-glib/mm-common-helpers.c | 60 ++++++++++++++++++++++++++++------ > src/mm-modem-helpers.c | 10 ++++-- > 2 files changed, 58 insertions(+), 12 deletions(-) >
Pushed to git master, thanks! > diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c > index 3470f64f..ed459c5a 100644 > --- a/libmm-glib/mm-common-helpers.c > +++ b/libmm-glib/mm-common-helpers.c > @@ -25,6 +25,26 @@ > #include "mm-errors-types.h" > #include "mm-common-helpers.h" > > +static int > +_enum_class_return_value (GEnumClass *enum_class, guint i) > +{ > + int value; > + > + value = enum_class->values[i].value; > + g_type_class_unref (enum_class); > + return value; > +} > + > +static int > +_flags_class_return_value (GFlagsClass *flags_class, guint i) > +{ > + guint value; > + > + value = flags_class->values[i].value; > + g_type_class_unref (flags_class); > + return value; > +} > + > gchar * > mm_common_build_capabilities_string (const MMModemCapability *capabilities, > guint n_capabilities) > @@ -795,9 +815,11 @@ mm_common_get_eps_ue_mode_operation_from_string (const > gchar *str, > > for (i = 0; enum_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick)) > - return enum_class->values[i].value; > + return _enum_class_return_value (enum_class, i); > } > > + g_type_class_unref (enum_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > @@ -914,9 +936,11 @@ mm_common_get_rm_protocol_from_string (const gchar *str, > > for (i = 0; enum_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick)) > - return enum_class->values[i].value; > + return _enum_class_return_value (enum_class, i); > } > > + g_type_class_unref (enum_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > @@ -936,9 +960,11 @@ mm_common_get_ip_type_from_string (const gchar *str, > > for (i = 0; flags_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, flags_class->values[i].value_nick)) > - return flags_class->values[i].value; > + return _flags_class_return_value (flags_class, i); > } > > + g_type_class_unref (flags_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > @@ -1008,9 +1034,11 @@ mm_common_get_sms_storage_from_string (const gchar > *str, > > for (i = 0; enum_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick)) > - return enum_class->values[i].value; > + return _enum_class_return_value (enum_class, i); > } > > + g_type_class_unref (enum_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > @@ -1030,9 +1058,11 @@ mm_common_get_sms_cdma_teleservice_id_from_string > (const gchar *str, > > for (i = 0; enum_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick)) > - return enum_class->values[i].value; > + return _enum_class_return_value (enum_class, i); > } > > + g_type_class_unref (enum_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > @@ -1052,9 +1082,11 @@ mm_common_get_sms_cdma_service_category_from_string > (const gchar *str, > > for (i = 0; enum_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick)) > - return enum_class->values[i].value; > + return _enum_class_return_value (enum_class, i); > } > > + g_type_class_unref (enum_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > @@ -1074,9 +1106,11 @@ mm_common_get_call_direction_from_string (const gchar > *str, > > for (i = 0; enum_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick)) > - return enum_class->values[i].value; > + return _enum_class_return_value (enum_class, i); > } > > + g_type_class_unref (enum_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > @@ -1096,9 +1130,11 @@ mm_common_get_call_state_from_string (const gchar *str, > > for (i = 0; enum_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick)) > - return enum_class->values[i].value; > + return _enum_class_return_value (enum_class, i); > } > > + g_type_class_unref (enum_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > @@ -1118,9 +1154,11 @@ mm_common_get_call_state_reason_from_string (const > gchar *str, > > for (i = 0; enum_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick)) > - return enum_class->values[i].value; > + return _enum_class_return_value (enum_class, i); > } > > + g_type_class_unref (enum_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > @@ -1190,9 +1228,11 @@ mm_common_get_oma_session_type_from_string (const > gchar *str, > > for (i = 0; enum_class->values[i].value_nick; i++) { > if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick)) > - return enum_class->values[i].value; > + return _enum_class_return_value (enum_class, i); > } > > + g_type_class_unref (enum_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c > index 35465d91..a1c7e9a2 100644 > --- a/src/mm-modem-helpers.c > +++ b/src/mm-modem-helpers.c > @@ -652,15 +652,21 @@ mm_flow_control_from_string (const gchar *str, > GError **error) > { > GFlagsClass *flags_class; > + guint value; > guint i; > > flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_FLOW_CONTROL)); > > for (i = 0; flags_class->values[i].value_nick; i++) { > - if (!g_ascii_strcasecmp (str, flags_class->values[i].value_nick)) > - return flags_class->values[i].value; > + if (!g_ascii_strcasecmp (str, flags_class->values[i].value_nick)) { > + value = flags_class->values[i].value; > + g_type_class_unref (flags_class); > + return value; > + } > } > > + g_type_class_unref (flags_class); > + > g_set_error (error, > MM_CORE_ERROR, > MM_CORE_ERROR_INVALID_ARGS, > -- Aleksander https://aleksander.es _______________________________________________ ModemManager-devel mailing list ModemManager-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel