From 28095476f5a76b9483e3ecc9b9a3ab7ddd4ff54b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 9 May 2012 18:27:14 +0000 Subject: [PATCH] -fixing #2329 --- src/util/server.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/util/server.c b/src/util/server.c index 0dd100ab7..fab68d46a 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -1251,6 +1251,25 @@ GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, } +/** + * Destroy the connection that is passed in via 'cls'. Used + * as calling 'GNUNET_CONNECTION_destroy' from within a function + * that was itself called from within 'process_notify' of + * 'connection.c' is not allowed (see #2329). + * + * @param cls connection to destroy + * @param tc scheduler context (unused) + */ +static void +destroy_connection (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_CONNECTION_Handle *connection = cls; + + GNUNET_CONNECTION_destroy (connection); +} + + /** * Ask the server to disconnect from the given client. * This is the same as returning GNUNET_SYSERR from a message @@ -1338,7 +1357,8 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client) GNUNET_CONNECTION_persist_ (client->connection); if (NULL != client->th.cth) GNUNET_SERVER_notify_transmit_ready_cancel (&client->th); - GNUNET_CONNECTION_destroy (client->connection); + (void) GNUNET_SCHEDULER_add_now (&destroy_connection, + client->connection); GNUNET_free (client); /* we might be in soft-shutdown, test if we're done */ if (NULL != server) @@ -1375,14 +1395,12 @@ transmit_ready_callback_wrapper (void *cls, size_t size, void *buf) { struct GNUNET_SERVER_Client *client = cls; GNUNET_CONNECTION_TransmitReadyNotify callback; - size_t ret; client->th.cth = NULL; callback = client->th.callback; client->th.callback = NULL; client->last_activity = GNUNET_TIME_absolute_get (); - ret = callback (client->th.callback_cls, size, buf); - return ret; + return callback (client->th.callback_cls, size, buf); } -- 2.25.1