summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej S. Szmigiero <mail@maciej.szmigiero.name>2021-11-13 00:49:56 +0100
committerMaciej S. Szmigiero <mail@maciej.szmigiero.name>2021-11-16 00:55:27 +0100
commite7d71c7fe25d3ae983120e43453c2b59f4bdbf75 (patch)
treefedaa669c3e426af884cd57c7bff49fafafd624c
parent5a3f7ffc36ea158f8ebb90e81c0604030c8b390a (diff)
Fix various memory leaks as reported by Valgrind
Reduces memory usage considerably for me: from 370 MiB RSS to just 24 MiB after a day.
-rw-r--r--src/gclue-modem-gps.c2
-rw-r--r--src/gclue-modem-manager.c11
-rw-r--r--src/gclue-nmea-source.c2
-rw-r--r--src/gclue-service-manager.c2
-rw-r--r--src/gclue-web-source.c6
5 files changed, 12 insertions, 11 deletions
diff --git a/src/gclue-modem-gps.c b/src/gclue-modem-gps.c
index 78d5e2f..ce4967a 100644
--- a/src/gclue-modem-gps.c
+++ b/src/gclue-modem-gps.c
@@ -214,7 +214,7 @@ on_fix_gps (GClueModem *modem,
{
GClueLocationSource *source = GCLUE_LOCATION_SOURCE (user_data);
GClueLocation *prev_location;
- GClueLocation *location;
+ g_autoptr(GClueLocation) location = NULL;
GError *error = NULL;
prev_location = gclue_location_source_get_location (source);
diff --git a/src/gclue-modem-manager.c b/src/gclue-modem-manager.c
index 847efb4..c1fa6da 100644
--- a/src/gclue-modem-manager.c
+++ b/src/gclue-modem-manager.c
@@ -304,7 +304,7 @@ on_get_3gpp_ready (GObject *source_object,
GClueModemManager *manager = GCLUE_MODEM_MANAGER (user_data);
GClueModemManagerPrivate *priv = manager->priv;
MMModemLocation *modem_location = MM_MODEM_LOCATION (source_object);
- MMLocation3gpp *location_3gpp;
+ g_autoptr(MMLocation3gpp) location_3gpp = NULL;
GError *error = NULL;
guint mcc, mnc;
gulong lac, cell_id;
@@ -345,7 +345,7 @@ on_get_3gpp_ready (GObject *source_object,
return;
}
g_clear_object (&priv->location_3gpp);
- priv->location_3gpp = location_3gpp;
+ priv->location_3gpp = g_steal_pointer (&location_3gpp);
g_signal_emit (manager, signals[FIX_3G], 0, mcc, mnc, lac, cell_id, tec);
}
@@ -357,7 +357,7 @@ on_get_cdma_ready (GObject *source_object,
{
GClueModemManager *manager = GCLUE_MODEM_MANAGER (user_data);
MMModemLocation *modem_location = MM_MODEM_LOCATION (source_object);
- MMLocationCdmaBs *location_cdma;
+ g_autoptr(MMLocationCdmaBs) location_cdma = NULL;
GError *error = NULL;
location_cdma = mm_modem_location_get_cdma_bs_finish (modem_location,
@@ -404,7 +404,7 @@ on_get_gps_nmea_ready (GObject *source_object,
GClueModemManager *manager = GCLUE_MODEM_MANAGER (user_data);
GClueModemManagerPrivate *priv = manager->priv;
MMModemLocation *modem_location = MM_MODEM_LOCATION (source_object);
- MMLocationGpsNmea *location_nmea;
+ g_autoptr(MMLocationGpsNmea) location_nmea = NULL;
static const gchar *sentences[3];
const gchar *gga, *rmc;
gint i = 0;
@@ -429,7 +429,6 @@ on_get_gps_nmea_ready (GObject *source_object,
if (gga != NULL && gclue_nmea_is_gga (gga)) {
if (is_location_gga_same (manager, gga)) {
g_debug ("New GGA trace is same as last one: %s", gga);
- g_object_unref (location_nmea);
return;
}
g_debug ("New GPGGA trace: %s", gga);
@@ -448,7 +447,7 @@ on_get_gps_nmea_ready (GObject *source_object,
g_signal_emit (manager, signals[FIX_GPS], 0, sentences);
g_clear_object (&priv->location_nmea);
- priv->location_nmea = location_nmea;
+ priv->location_nmea = g_steal_pointer (&location_nmea);
}
static void
diff --git a/src/gclue-nmea-source.c b/src/gclue-nmea-source.c
index af294b4..f5a5c45 100644
--- a/src/gclue-nmea-source.c
+++ b/src/gclue-nmea-source.c
@@ -458,7 +458,7 @@ on_read_nmea_sentence (GObject *object,
GDataInputStream *data_input_stream = G_DATA_INPUT_STREAM (object);
GError *error = NULL;
GClueLocation *prev_location;
- GClueLocation *location;
+ g_autoptr(GClueLocation) location = NULL;
gsize data_size = 0 ;
char *message;
gint i;
diff --git a/src/gclue-service-manager.c b/src/gclue-service-manager.c
index efcf5ce..016cd3f 100644
--- a/src/gclue-service-manager.c
+++ b/src/gclue-service-manager.c
@@ -127,7 +127,7 @@ delete_client (GClueServiceManager *manager,
if (compare_func (l->data, compare_func_data) == 0) {
g_object_unref (G_OBJECT (l->data));
- priv->clients = g_list_remove_link (priv->clients, l);
+ priv->clients = g_list_delete_link (priv->clients, l);
priv->num_clients--;
if (priv->num_clients == 0) {
g_object_notify (G_OBJECT (manager), "active");
diff --git a/src/gclue-web-source.c b/src/gclue-web-source.c
index a63b770..bfd70f7 100644
--- a/src/gclue-web-source.c
+++ b/src/gclue-web-source.c
@@ -335,18 +335,20 @@ submit_query_callback (SoupSession *session,
gpointer user_data)
{
SoupURI *uri;
+ g_autofree char *str = NULL;
uri = soup_message_get_uri (query);
+ str = soup_uri_to_string (uri, FALSE);
if (query->status_code != SOUP_STATUS_OK &&
query->status_code != SOUP_STATUS_NO_CONTENT) {
g_warning ("Failed to submit location data to '%s': %s",
- soup_uri_to_string (uri, FALSE),
+ str,
query->reason_phrase);
return;
}
g_debug ("Successfully submitted location data to '%s'",
- soup_uri_to_string (uri, FALSE));
+ str);
}
#define SUBMISSION_ACCURACY_THRESHOLD 100