]> granicus.if.org Git - libevent/commitdiff
Try to untangle the logic in server_port_flush().
authorNick Mathewson <nickm@torproject.org>
Mon, 25 Jan 2010 19:07:01 +0000 (14:07 -0500)
committerNick Mathewson <nickm@torproject.org>
Mon, 25 Jan 2010 19:07:01 +0000 (14:07 -0500)
The logic that prevented the first loop in this function from being
infinite was rather confusing and hard to follow.  It seems to confuse
some automatic analysis tools as well as me.  Let's try to replace it
with something more comprehensible.

evdns.c

diff --git a/evdns.c b/evdns.c
index 29ea5432a0c3ba88ab15adeffcf9205c95ba74b8..6afe75576cee2864c77fbfdb2eca488675fc35c8 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -1418,9 +1418,9 @@ server_port_read(struct evdns_server_port *s) {
 static void
 server_port_flush(struct evdns_server_port *port)
 {
+       struct server_request *req = port->pending_replies;
        ASSERT_LOCKED(port);
-       while (port->pending_replies) {
-               struct server_request *req = port->pending_replies;
+       while (req) {
                int r = sendto(port->socket, req->response, req->response_len, 0,
                           (struct sockaddr*) &req->addr, req->addrlen);
                if (r < 0) {
@@ -1432,6 +1432,9 @@ server_port_flush(struct evdns_server_port *port)
                if (server_request_free(req)) {
                        /* we released the last reference to req->port. */
                        return;
+               } else {
+                       EVUTIL_ASSERT(req != port->pending_replies);
+                       req = port->pending_replies;
                }
        }