exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit b7e6a5b5731221204488abeed84663c715b166e2
parent f2948bd521eff23cc81ea722ae66f7e2635ad2a8
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 31 Jan 2026 23:08:49 +0100

proper fix for the race issue

Diffstat:
Msrc/util/secmod_common.c | 73+++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 35 insertions(+), 38 deletions(-)

diff --git a/src/util/secmod_common.c b/src/util/secmod_common.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2020 Taler Systems SA + Copyright (C) 2020, 2026 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -402,20 +402,39 @@ sign_worker (void *cls) break; } } - GNUNET_assert (0 == pthread_mutex_lock (&TES_clients_lock)); GNUNET_break (0 == close (client->csock)); client->csock = -1; + return NULL; +} + + +/** + * Clean up @a pos, joining the thread and closing the + * file descriptors. + * + * @param[in] pos client to clean up + */ +static void +join_client (struct TES_Client *pos) +{ + void *rval; + + GNUNET_CONTAINER_DLL_remove (TES_clients_head, + TES_clients_tail, + pos); + GNUNET_break (0 == + pthread_join (pos->worker, + &rval)); #ifdef __linux__ - GNUNET_break (0 == close (client->esock)); - client->esock = -1; + GNUNET_break (0 == close (pos->esock)); + pos->esock = -1; #else - GNUNET_break (0 == close (client->esock_in)); - client->esock_in = -1; - GNUNET_break (0 == close (client->esock_out)); - client->esock_out = -1; + GNUNET_break (0 == close (pos->esock_in)); + pos->esock_in = -1; + GNUNET_break (0 == close (pos->esock_out)); + pos->esock_out = -1; #endif - GNUNET_assert (0 == pthread_mutex_unlock (&TES_clients_lock)); - return NULL; + GNUNET_free (pos); } @@ -497,15 +516,7 @@ listen_job (void *cls) nxt = pos->next; if (-1 == pos->csock) { - void *rval; - - GNUNET_CONTAINER_DLL_remove (TES_clients_head, - TES_clients_tail, - pos); - GNUNET_break (0 == - pthread_join (pos->worker, - &rval)); - GNUNET_free (pos); + join_client (pos); } } GNUNET_CONTAINER_DLL_insert (TES_clients_head, @@ -525,16 +536,12 @@ listen_job (void *cls) TES_clients_tail, client); GNUNET_assert (0 == pthread_mutex_unlock (&TES_clients_lock)); - if (-1 != client->csock) - GNUNET_break (0 == close (client->csock)); + GNUNET_break (0 == close (client->csock)); #ifdef __linux__ - if (-1 != client->esock) - GNUNET_break (0 == close (client->esock)); + GNUNET_break (0 == close (client->esock)); #else - if (-1 != client->esock_in) - GNUNET_break (0 == close (client->esock_in)); - if (-1 != client->esock_out) - GNUNET_break (0 == close (client->esock_out)); + GNUNET_break (0 == close (client->esock_in)); + GNUNET_break (0 == close (client->esock_out)); #endif GNUNET_free (client); } @@ -633,16 +640,6 @@ TES_listen_stop (void) TES_wake_clients (); GNUNET_assert (0 == pthread_mutex_lock (&TES_clients_lock)); while (NULL != (client = TES_clients_head)) - { - void *rval; - - GNUNET_CONTAINER_DLL_remove (TES_clients_head, - TES_clients_tail, - client); - GNUNET_break (0 == - pthread_join (client->worker, - &rval)); - GNUNET_free (client); - } + join_client (client); GNUNET_assert (0 == pthread_mutex_unlock (&TES_clients_lock)); }