diff --git a/document-portal/file-transfer.c b/document-portal/file-transfer.c index 74eba99ab..73e2298c8 100644 --- a/document-portal/file-transfer.c +++ b/document-portal/file-transfer.c @@ -25,6 +25,7 @@ #include "config.h" #include +#include #include #include #include @@ -144,7 +145,7 @@ static GHashTable *transfers; static FileTransfer * lookup_transfer (const char *key) { - FileTransfer *transfer; + g_autoptr(FileTransfer) transfer = NULL; G_LOCK (transfers); transfer = (FileTransfer *)g_hash_table_lookup (transfers, key); @@ -152,7 +153,7 @@ lookup_transfer (const char *key) g_object_ref (transfer); G_UNLOCK (transfers); - return transfer; + return g_steal_pointer (&transfer); } static FileTransfer * @@ -172,13 +173,14 @@ file_transfer_start (XdpAppInfo *app_info, transfer->files = g_ptr_array_new_with_free_func (exported_file_free); G_LOCK (transfers); - do { - guint64 key; - g_free (transfer->key); - key = g_random_int (); - key = (key << 32) | g_random_int (); - transfer->key = g_strdup_printf ("%" G_GUINT64_FORMAT, key); - } + do + { + uint64_t key; + g_free (transfer->key); + key = g_random_int (); + key = (key << 32) | g_random_int (); + transfer->key = g_strdup_printf ("%" G_GUINT64_FORMAT, key); + } while (g_hash_table_contains (transfers, transfer->key)); g_hash_table_insert (transfers, transfer->key, g_object_ref (transfer)); G_UNLOCK (transfers); @@ -227,9 +229,9 @@ file_transfer_stop (FileTransfer *transfer) static void file_transfer_add_file (FileTransfer *transfer, - const char *path, - struct stat *st_buf, - struct stat *parent_st_buf) + const char *path, + struct stat *st_buf, + struct stat *parent_st_buf) { ExportedFile *file; @@ -243,9 +245,9 @@ file_transfer_add_file (FileTransfer *transfer, } static char ** -file_transfer_execute (FileTransfer *transfer, - XdpAppInfo *target_app_info, - GError **error) +file_transfer_execute (FileTransfer *transfer, + XdpAppInfo *target_app_info, + GError **error) { DocumentAddFullFlags common_flags; DocumentPermissionFlags perms; @@ -338,8 +340,8 @@ file_transfer_execute (FileTransfer *transfer, static void start_transfer (GDBusMethodInvocation *invocation, - GVariant *parameters, - XdpAppInfo *app_info) + GVariant *parameters, + XdpAppInfo *app_info) { g_autoptr(GVariant) options = NULL; g_autoptr(FileTransfer) transfer = NULL; @@ -363,8 +365,8 @@ start_transfer (GDBusMethodInvocation *invocation, static void add_files (GDBusMethodInvocation *invocation, - GVariant *parameters, - XdpAppInfo *app_info) + GVariant *parameters, + XdpAppInfo *app_info) { FileTransfer *transfer; const char *key; @@ -456,8 +458,8 @@ add_files (GDBusMethodInvocation *invocation, static void retrieve_files (GDBusMethodInvocation *invocation, - GVariant *parameters, - XdpAppInfo *app_info) + GVariant *parameters, + XdpAppInfo *app_info) { const char *key; FileTransfer *transfer; @@ -490,8 +492,8 @@ retrieve_files (GDBusMethodInvocation *invocation, static void stop_transfer (GDBusMethodInvocation *invocation, - GVariant *parameters, - XdpAppInfo *app_info) + GVariant *parameters, + XdpAppInfo *app_info) { const char *key; FileTransfer *transfer; @@ -553,7 +555,7 @@ file_transfer_create (void) return G_DBUS_INTERFACE_SKELETON (file_transfer); } -void +static void stop_file_transfers_in_thread_func (GTask *task, gpointer source_object, gpointer task_data, @@ -583,10 +585,9 @@ stop_file_transfers_in_thread_func (GTask *task, void stop_file_transfers_for_sender (const char *sender) { - GTask *task; + g_autoptr(GTask) task = NULL; task = g_task_new (NULL, NULL, NULL, NULL); g_task_set_task_data (task, g_strdup (sender), g_free); g_task_run_in_thread (task, stop_file_transfers_in_thread_func); - g_object_unref (task); }