smbd: Fix a use-after-free
[mat/samba.git] / source3 / smbd / server_exit.c
index d48a8f283d298248f1c769f48866b7b6271000ec..6a51c24f549984f0ef7e21160661f49e18cdb762 100644 (file)
@@ -218,7 +218,10 @@ static void exit_server_common(enum server_exit_reason how,
         * because smbd_msg_ctx is not a talloc child of smbd_server_conn.
         */
        if (client != NULL) {
-               for (; xconn != NULL; xconn = xconn->next) {
+               struct smbXsrv_connection *next;
+
+               for (; xconn != NULL; xconn = next) {
+                       next = xconn->next;
                        DLIST_REMOVE(client->connections, xconn);
                        talloc_free(xconn);
                }