From 3fc8fe101fd93605cb3d1e301ee8e552a9601338 Mon Sep 17 00:00:00 2001 From: "Maciej S. Szmigiero" Date: Thu, 12 Jan 2023 23:27:16 +0100 Subject: Use automatic char* memory management where possible Remove explicit g_free () calls and convert char* allocations to g_autofree. Fixes at least one memory leak in gclue_service_agent_handle_authorize_app (). --- src/gclue-location.c | 3 +-- src/gclue-service-client.c | 14 ++++++-------- src/gclue-service-manager.c | 3 +-- 3 files changed, 8 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/gclue-location.c b/src/gclue-location.c index 84062cb..b5f9869 100644 --- a/src/gclue-location.c +++ b/src/gclue-location.c @@ -425,7 +425,7 @@ parse_coordinate_string (const char *coordinate, const char *direction) { gdouble minutes, degrees, out; - gchar *degrees_str; + g_autofree gchar *degrees_str = NULL; gchar *dot_str; gint dot_offset; @@ -450,7 +450,6 @@ parse_coordinate_string (const char *coordinate, degrees_str = g_strndup (coordinate, dot_offset - 2); degrees = g_ascii_strtod (degrees_str, NULL); - g_free (degrees_str); minutes = g_ascii_strtod (dot_str - 2, NULL); diff --git a/src/gclue-service-client.c b/src/gclue-service-client.c index cd56179..9908994 100644 --- a/src/gclue-service-client.c +++ b/src/gclue-service-client.c @@ -86,13 +86,13 @@ static char * next_location_path (GClueServiceClient *client) { GClueServiceClientPrivate *priv = client->priv; - char *path, *index_str; + g_autofree char *index_str = NULL; + g_autofree char *path = NULL; index_str = g_strdup_printf ("%u", (priv->locations_updated)++), path = g_strjoin ("/", priv->path, "Location", index_str, NULL); - g_free (index_str); - return path; + return g_steal_pointer (&path); } /* We don't use the gdbus-codegen provided gclue_client_emit_location_updated() @@ -201,7 +201,7 @@ on_locator_location_changed (GObject *gobject, GClueServiceClientPrivate *priv = client->priv; GClueLocationSource *locator = GCLUE_LOCATION_SOURCE (gobject); GClueLocation *new_location; - char *path = NULL; + g_autofree char *path = NULL; const char *prev_path; g_autoptr(GError) error = NULL; @@ -245,12 +245,10 @@ on_locator_location_changed (GObject *gobject, if (!emit_location_updated (client, prev_path, path, &error)) goto error_out; - goto out; + return; error_out: g_warning ("Failed to update location info: %s", error->message); -out: - g_free (path); } static void @@ -374,7 +372,7 @@ start_data_free (StartData *data) { g_object_unref (data->client); g_object_unref (data->invocation); - g_free(data->desktop_id); + g_free (data->desktop_id); g_slice_free (StartData, data); } diff --git a/src/gclue-service-manager.c b/src/gclue-service-manager.c index 9f44a56..d6ac494 100644 --- a/src/gclue-service-manager.c +++ b/src/gclue-service-manager.c @@ -181,7 +181,7 @@ complete_get_client (OnClientInfoNewReadyData *data) GClueClientInfo *info = data->client_info; GClueAgent *agent_proxy = NULL; g_autoptr(GError) error = NULL; - char *path; + g_autofree char *path = NULL; guint32 user_id; /* Disconnect on_peer_vanished_before_completion, if it's there */ @@ -257,7 +257,6 @@ error_out: out: g_clear_object (&info); on_client_info_new_ready_data_free (data); - g_free (path); return FALSE; } -- cgit v1.2.1