From: Arran Cudbard-Bell Date: Wed, 11 Jul 2018 20:23:49 +0000 (-0400) Subject: Don't return early if we have entries to free X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e729f20b3626e2e796c8fc474fdb34d632f25b19;p=thirdparty%2Ffreeradius-server.git Don't return early if we have entries to free --- diff --git a/src/main/state.c b/src/main/state.c index 3785584dba4..aa5f102bea5 100644 --- a/src/main/state.c +++ b/src/main/state.c @@ -320,6 +320,8 @@ static fr_state_entry_t *state_entry_create(fr_state_tree_t *state, REQUEST *req uint8_t old_state[sizeof(old->state)]; int old_tries = 0; + bool too_many = false; + /* * Clean up old entries. @@ -343,11 +345,7 @@ static fr_state_entry_t *state_entry_create(fr_state_tree_t *state, REQUEST *req break; } - if (rbtree_num_elements(state->tree) >= (uint32_t) state->max_sessions) { - RERROR("Failed inserting state entry - At maximum ongoing session limit (%u)", - state->max_sessions); - return NULL; - } + if (rbtree_num_elements(state->tree) >= (uint32_t) state->max_sessions) too_many = true; /* * Record the information from the old state, we may base the @@ -387,6 +385,17 @@ static fr_state_entry_t *state_entry_create(fr_state_tree_t *state, REQUEST *req talloc_free(entry); } + /* + * Have to do this post-cleanup, else we end up returning with + * a list full of entries to free with none of them being + * freed which is bad... + */ + if (too_many) { + RERROR("Failed inserting state entry - At maximum ongoing session limit (%u)", + state->max_sessions); + return NULL; + } + /* * Allocation doesn't need to occur inside the critical region * and would add significantly to contention.