From fd4166279bd47e92047a4a0ef7bc6634a0b9e585 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Wed, 3 Oct 2018 17:04:24 +0200 Subject: [PATCH] gamemode: Convert game_mode_context_has_client() to return the client Returning a bool is not useful if we want to create some log information from this. It now returns NULL or a client pointer which is compatible with all of the current users. When dereferencing the returned pointer, a read lock must be acquired around using the returned result as the client may be deallocated from heap otherwise. Signed-off-by: Kai Krakow --- daemon/gamemode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/daemon/gamemode.c b/daemon/gamemode.c index e1755f6..dc15091 100644 --- a/daemon/gamemode.c +++ b/daemon/gamemode.c @@ -131,7 +131,7 @@ static volatile bool had_context_init = false; static GameModeClient *game_mode_client_new(pid_t pid, char *exe); static void game_mode_client_free(GameModeClient *client); -static bool game_mode_context_has_client(GameModeContext *self, pid_t client); +static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client); static int game_mode_context_num_clients(GameModeContext *self); static void *game_mode_context_reaper(void *userdata); static void game_mode_context_enter(GameModeContext *self); @@ -439,15 +439,15 @@ static void game_mode_context_auto_expire(GameModeContext *self) /** * Determine if the client is already known to the context */ -static bool game_mode_context_has_client(GameModeContext *self, pid_t client) +static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client) { - bool found = false; + const GameModeClient *found = NULL; pthread_rwlock_rdlock(&self->rwlock); /* Walk all clients and find a matching pid */ for (GameModeClient *cl = self->client; cl; cl = cl->next) { if (cl->pid == client) { - found = true; + found = cl; break; } }