]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
check child state_ctx against parent
authorAlan T. DeKok <aland@freeradius.org>
Tue, 1 Oct 2019 13:43:40 +0000 (09:43 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 1 Oct 2019 13:53:00 +0000 (09:53 -0400)
The EAP code should arguably call request_detach() or something,
but this is a quick and easy fix

src/lib/server/request.c

index 2c2f0fe661c949ae2d82dcd6c542da8584134de2..bfec99e17a9e83d04cd6f9d8c956299a3f584397 100644 (file)
@@ -50,8 +50,24 @@ static int _request_free(REQUEST *request)
         *      need to persist across requests, they will already have been
         *      moved to a fr_state_entry_t, with the state pointers in the
         *      request being set to NULL, before the request is freed.
+        *
+        *      Our state ctx can be the same as the parents if
+        *      request_data_restore_to_child() was called.  That
+        *      function resets the childs state_ctx to be the same as
+        *      the parents.  Adding this check here means that we
+        *      don't need to call request_detach() on a child which
+        *      will be freed immediately after the detach.
+        *
+        *      Note also that we do NOT call TALLOC_FREE(), which
+        *      sets state_ctx=NULL.  We don't control the order in
+        *      which talloc frees the children.  And the parents
+        *      state_ctx pointer needs to stick around so that all of
+        *      the children can check it.
         */
-       if (request->state_ctx) TALLOC_FREE(request->state_ctx);
+       if (request->state_ctx &&
+           (!request->parent || (request->parent->state_ctx != request->state_ctx))) {
+               talloc_free(request->state_ctx);
+       }
 
        talloc_free_children(request);