From 5575070ffea92be7b42b3f23f6918135d923270b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 13 Oct 2011 20:04:52 +0000 Subject: [PATCH] fix stack overflow --- src/ats/ats_api_scheduling.c | 43 ++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index 07d4d85d4..6c4441d81 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c @@ -105,6 +105,11 @@ struct GNUNET_ATS_SchedulingHandle * Unused entries are also NULL. */ struct Session **session_array; + + /** + * Task to trigger reconnect. + */ + GNUNET_SCHEDULER_TaskIdentifier task; /** * Size of the session array. @@ -123,6 +128,24 @@ static void reconnect (struct GNUNET_ATS_SchedulingHandle *sh); + +/** + * Re-establish the connection to the ATS service. + * + * @param cls handle to use to re-connect. + * @param tc scheduler context + */ +static void +reconnect_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_ATS_SchedulingHandle *sh = cls; + + sh->task = GNUNET_SCHEDULER_NO_TASK; + reconnect (sh); +} + + /** * Transmit messages from the message queue to the service * (if there are any, and if we are not already trying). @@ -289,7 +312,8 @@ process_ats_message (void *cls, { GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); sh->client = NULL; - reconnect (sh); + sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &reconnect_task, sh); return; } if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || @@ -298,7 +322,8 @@ process_ats_message (void *cls, GNUNET_break (0); GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); sh->client = NULL; - reconnect (sh); + sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &reconnect_task, sh); return; } m = (const struct AddressSuggestionMessage*) msg; @@ -318,7 +343,8 @@ process_ats_message (void *cls, GNUNET_break (0); GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); sh->client = NULL; - reconnect (sh); + sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &reconnect_task, sh); return; } sh->suggest_cb (sh->suggest_cb_cls, @@ -416,7 +442,16 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) p); GNUNET_free (p); } - GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); + if (NULL != sh->client) + { + GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); + sh->client = NULL; + } + if (GNUNET_SCHEDULER_NO_TASK != sh->task) + { + GNUNET_SCHEDULER_cancel (sh->task); + sh->task = GNUNET_SCHEDULER_NO_TASK; + } GNUNET_array_grow (sh->session_array, sh->session_array_size, 0); -- 2.25.1