diff options
author | Maciej S. Szmigiero <maciej.szmigiero@oracle.com> | 2023-01-12 23:27:16 +0100 |
---|---|---|
committer | Maciej S. Szmigiero <maciej.szmigiero@oracle.com> | 2023-01-14 00:49:52 +0100 |
commit | 3fc8fe101fd93605cb3d1e301ee8e552a9601338 (patch) | |
tree | 6780659015b57a7f82b076189abf8b343b084d1d | |
parent | ca72db0f8b53deacb93f57f3015bc4c9ffc14335 (diff) | |
download | geoclue-3fc8fe101fd93605cb3d1e301ee8e552a9601338.tar.gz |
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 ().
-rw-r--r-- | demo/gclue-service-agent.c | 15 | ||||
-rw-r--r-- | demo/where-am-i.c | 3 | ||||
-rw-r--r-- | libgeoclue/gclue-helpers.c | 3 | ||||
-rw-r--r-- | src/gclue-location.c | 3 | ||||
-rw-r--r-- | src/gclue-service-client.c | 14 | ||||
-rw-r--r-- | src/gclue-service-manager.c | 3 |
6 files changed, 17 insertions, 24 deletions
diff --git a/demo/gclue-service-agent.c b/demo/gclue-service-agent.c index 0c5c08d..8758721 100644 --- a/demo/gclue-service-agent.c +++ b/demo/gclue-service-agent.c @@ -334,10 +334,10 @@ gclue_service_agent_handle_authorize_app (GClueAgent *agent, NotifyNotification *notification; NotificationData *data; GError *error = NULL; - char *desktop_file; + g_autofree char *desktop_file = NULL; GDesktopAppInfo *app_info; - char *msg; - const char *reason; + g_autofree char *msg = NULL; + g_autofree char *reason = NULL; desktop_file = g_strjoin (".", desktop_id, "desktop", NULL); app_info = g_desktop_app_info_new (desktop_file); @@ -350,18 +350,17 @@ gclue_service_agent_handle_authorize_app (GClueAgent *agent, return TRUE; } - g_free (desktop_file); msg = g_strdup_printf (_("Allow '%s' to access your location information?"), g_app_info_get_display_name (G_APP_INFO (app_info))); reason = g_desktop_app_info_get_string (app_info, "X-Geoclue-Reason"); if (reason != NULL) { - char *tmp = msg; - msg = g_strdup_printf ("%s\n\n%s", msg, reason); - g_free (tmp); + char *tmp = g_strdup_printf ("%s\n\n%s", msg, reason); + + g_clear_pointer (&msg, g_free); + msg = tmp; } notification = notify_notification_new (_("Geolocation"), msg, "dialog-question"); - g_free (msg); data = g_slice_new0 (NotificationData); data->invocation = invocation; diff --git a/demo/where-am-i.c b/demo/where-am-i.c index aa873a4..a75441c 100644 --- a/demo/where-am-i.c +++ b/demo/where-am-i.c @@ -111,7 +111,7 @@ print_location (GClueSimple *simple) if (timestamp) { GDateTime *date_time; guint64 sec, usec; - gchar *str; + g_autofree gchar *str = NULL; g_variant_get (timestamp, "(tt)", &sec, &usec); @@ -123,7 +123,6 @@ print_location (GClueSimple *simple) g_date_time_unref (date_time); g_print ("Timestamp: %s\n", str); - g_free (str); } } diff --git a/libgeoclue/gclue-helpers.c b/libgeoclue/gclue-helpers.c index bbb3809..de92b38 100644 --- a/libgeoclue/gclue-helpers.c +++ b/libgeoclue/gclue-helpers.c @@ -161,7 +161,7 @@ on_get_client_ready (GObject *source_object, { GTask *task = G_TASK (user_data); GClueManager *manager = GCLUE_MANAGER (source_object); - char *client_path; + g_autofree char *client_path = NULL; GError *error = NULL; if (!gclue_manager_call_get_client_finish (manager, @@ -182,7 +182,6 @@ on_get_client_ready (GObject *source_object, g_task_get_cancellable (task), on_client_proxy_ready, task); - g_free (client_path); g_object_unref (manager); } 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; } |