dnsproxy: If no request was sent then the TCP server is destroyed
authorPaulo Pizarro <paulo.pizarro@gmail.com>
Mon, 18 Jun 2012 02:22:37 +0000 (23:22 -0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 18 Jun 2012 10:31:49 +0000 (13:31 +0300)
src/dnsproxy.c

index 71efe6a..58d1bfe 100644 (file)
@@ -1791,6 +1791,7 @@ hangup:
        if ((condition & G_IO_OUT) && !server->connected) {
                GSList *list;
                GList *domains;
        if ((condition & G_IO_OUT) && !server->connected) {
                GSList *list;
                GList *domains;
+               int no_request_sent = TRUE;
                struct server_data *udp_server;
 
                udp_server = find_server(server->interface, server->server,
                struct server_data *udp_server;
 
                udp_server = find_server(server->interface, server->server,
@@ -1818,6 +1819,7 @@ hangup:
 
                for (list = request_list; list; ) {
                        struct request_data *req = list->data;
 
                for (list = request_list; list; ) {
                        struct request_data *req = list->data;
+                       int status;
 
                        if (req->protocol == IPPROTO_UDP) {
                                list = list->next;
 
                        if (req->protocol == IPPROTO_UDP) {
                                list = list->next;
@@ -1826,8 +1828,9 @@ hangup:
 
                        DBG("Sending req %s over TCP", (char *)req->name);
 
 
                        DBG("Sending req %s over TCP", (char *)req->name);
 
-                       if (ns_resolv(server, req,
-                                       req->request, req->name) > 0) {
+                       status = ns_resolv(server, req,
+                                               req->request, req->name);
+                       if (status > 0) {
                                /*
                                 * A cached result was sent,
                                 * so the request can be released
                                /*
                                 * A cached result was sent,
                                 * so the request can be released
@@ -1838,6 +1841,13 @@ hangup:
                                continue;
                        }
 
                                continue;
                        }
 
+                       if (status < 0) {
+                               list = list->next;
+                               continue;
+                       }
+
+                       no_request_sent = FALSE;
+
                        if (req->timeout > 0)
                                g_source_remove(req->timeout);
 
                        if (req->timeout > 0)
                                g_source_remove(req->timeout);
 
@@ -1846,6 +1856,11 @@ hangup:
                        list = list->next;
                }
 
                        list = list->next;
                }
 
+               if (no_request_sent == TRUE) {
+                       destroy_server(server);
+                       return FALSE;
+               }
+
        } else if (condition & G_IO_IN) {
                struct partial_reply *reply = server->incoming_reply;
                int bytes_recv;
        } else if (condition & G_IO_IN) {
                struct partial_reply *reply = server->incoming_reply;
                int bytes_recv;