iface-modem-location: plug memleaks when updating gps raw variant

The helper method returning a variant from a MMLocationGpsRaw would
return already a full variant reference instead of a floating one, so
we were really increasing the refcount when doing g_variant_ref_sink()
in the location interface.

Fix this by consolidating all helper methods in libmm-glib that return
variants from the different MMLocationXX objects, so that they all
return full variants instead of floating ones.
This commit is contained in:
Aleksander Morgado
2020-02-07 15:11:53 +01:00
parent a7a8fc909a
commit a61caff747
3 changed files with 6 additions and 10 deletions

View File

@@ -291,7 +291,7 @@ mm_location_3gpp_get_string_variant (MMLocation3gpp *self)
self->priv->cell_id, self->priv->cell_id,
self->priv->tracking_area_code); self->priv->tracking_area_code);
variant = g_variant_new_string (str); variant = g_variant_ref_sink (g_variant_new_string (str));
g_free (str); g_free (str);
} }

View File

@@ -244,7 +244,7 @@ mm_location_gps_nmea_get_string_variant (MMLocationGpsNmea *self)
traces = mm_location_gps_nmea_get_traces (self); traces = mm_location_gps_nmea_get_traces (self);
built = g_strjoinv ("\r\n", traces); built = g_strjoinv ("\r\n", traces);
return g_variant_new_string (built); return g_variant_ref_sink (g_variant_new_string (built));
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -165,11 +165,10 @@ build_location_dictionary (GVariant *previous,
if (location_3gpp_value) if (location_3gpp_value)
g_variant_unref (location_3gpp_value); g_variant_unref (location_3gpp_value);
location_3gpp_value = mm_location_3gpp_get_string_variant (location_3gpp); location_3gpp_value = mm_location_3gpp_get_string_variant (location_3gpp);
if (location_3gpp_value)
g_variant_ref_sink (location_3gpp_value);
} }
if (location_3gpp_value) { if (location_3gpp_value) {
g_assert (!g_variant_is_floating (location_3gpp_value));
g_variant_builder_add (&builder, g_variant_builder_add (&builder,
"{uv}", "{uv}",
MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI, MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI,
@@ -182,11 +181,10 @@ build_location_dictionary (GVariant *previous,
if (location_gps_nmea_value) if (location_gps_nmea_value)
g_variant_unref (location_gps_nmea_value); g_variant_unref (location_gps_nmea_value);
location_gps_nmea_value = mm_location_gps_nmea_get_string_variant (location_gps_nmea); location_gps_nmea_value = mm_location_gps_nmea_get_string_variant (location_gps_nmea);
if (location_gps_nmea_value)
g_variant_ref_sink (location_gps_nmea_value);
} }
if (location_gps_nmea_value) { if (location_gps_nmea_value) {
g_assert (!g_variant_is_floating (location_gps_nmea_value));
g_variant_builder_add (&builder, g_variant_builder_add (&builder,
"{uv}", "{uv}",
MM_MODEM_LOCATION_SOURCE_GPS_NMEA, MM_MODEM_LOCATION_SOURCE_GPS_NMEA,
@@ -199,11 +197,10 @@ build_location_dictionary (GVariant *previous,
if (location_gps_raw_value) if (location_gps_raw_value)
g_variant_unref (location_gps_raw_value); g_variant_unref (location_gps_raw_value);
location_gps_raw_value = mm_location_gps_raw_get_dictionary (location_gps_raw); location_gps_raw_value = mm_location_gps_raw_get_dictionary (location_gps_raw);
if (location_gps_raw_value)
g_variant_ref_sink (location_gps_raw_value);
} }
if (location_gps_raw_value) { if (location_gps_raw_value) {
g_assert (!g_variant_is_floating (location_gps_raw_value));
g_variant_builder_add (&builder, g_variant_builder_add (&builder,
"{uv}", "{uv}",
MM_MODEM_LOCATION_SOURCE_GPS_RAW, MM_MODEM_LOCATION_SOURCE_GPS_RAW,
@@ -216,11 +213,10 @@ build_location_dictionary (GVariant *previous,
if (location_cdma_bs_value) if (location_cdma_bs_value)
g_variant_unref (location_cdma_bs_value); g_variant_unref (location_cdma_bs_value);
location_cdma_bs_value = mm_location_cdma_bs_get_dictionary (location_cdma_bs); location_cdma_bs_value = mm_location_cdma_bs_get_dictionary (location_cdma_bs);
if (location_cdma_bs_value)
g_variant_ref_sink (location_cdma_bs_value);
} }
if (location_cdma_bs_value) { if (location_cdma_bs_value) {
g_assert (!g_variant_is_floating (location_cdma_bs_value));
g_variant_builder_add (&builder, g_variant_builder_add (&builder,
"{uv}", "{uv}",
MM_MODEM_LOCATION_SOURCE_CDMA_BS, MM_MODEM_LOCATION_SOURCE_CDMA_BS,