]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Bugfix 394 of leaking sockets:
authorWillem Toorop <willem@NLnetLabs.nl>
Tue, 28 Jun 2011 12:15:32 +0000 (12:15 +0000)
committerWillem Toorop <willem@NLnetLabs.nl>
Tue, 28 Jun 2011 12:15:32 +0000 (12:15 +0000)
when ldns_udp_send_query returned a error when used from ldns_udp_bgsend and ldns_tcp_bgsend, the newly created socket was not closed nor returned.
Now it is closed.

Changelog
net.c

index 62743918260b2b6f29ac70e0bd7fce6a252e23d1..4a89878526f2e4c792546be3c35fa5ce7802d09d 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,5 @@
 1.6.11
+       * bugfix #394: Fix socket leak on errors
 
 1.6.10 2011-05-31
        * New example tool added: ldns-gen-zone.
diff --git a/net.c b/net.c
index bf8766b9905415ec261b780de5e7070e5b79194d..8bae0b2cf8f553e52fa8851da861e7463413a799 100644 (file)
--- a/net.c
+++ b/net.c
@@ -341,6 +341,11 @@ ldns_udp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t
        }
 
        if (ldns_udp_send_query(qbin, sockfd, to, tolen) == 0) {
+               #ifndef USE_WINSOCK
+                       close(sockfd);
+               #else
+                       closesocket(sockfd);
+               #endif
                return 0;
        }
        return sockfd;
@@ -678,6 +683,11 @@ ldns_tcp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t
        }
        
        if (ldns_tcp_send_query(qbin, sockfd, to, tolen) == 0) {
+               #ifndef USE_WINSOCK
+                       close(sockfd);
+               #else
+                       closesocket(sockfd);
+               #endif
                return 0;
        }