]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Don't return early if we have entries to free
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 11 Jul 2018 20:23:49 +0000 (16:23 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 11 Jul 2018 20:23:49 +0000 (16:23 -0400)
src/main/state.c

index 3785584dba447424eaf777b243d433ac246a2202..aa5f102bea56477da83a0102900e8b39d26ea526 100644 (file)
@@ -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.