]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/io: tcp cleanup
authorMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 1 Apr 2015 15:09:02 +0000 (17:09 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 1 Apr 2015 15:09:02 +0000 (17:09 +0200)
daemon/io.c

index 88607dfdc451cb90d434bb9fe8c091d4ae63266b..666a39933f483e7f6f4201799de0971a576dadc0 100644 (file)
@@ -106,7 +106,6 @@ static void tcp_unbind_handle(uv_handle_t *handle)
 {
        uv_read_stop((uv_stream_t *)handle);
        buf_free(handle);
-       uv_close(handle, NULL);
 }
 
 static void tcp_send(uv_handle_t *handle, const knot_pkt_t *answer)
@@ -129,7 +128,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf)
        /* Check the incoming wire length (malformed, EOF or error). */
        if (nread < (ssize_t) sizeof(uint16_t)) {
                tcp_unbind_handle((uv_handle_t *)handle);
-               free(handle);
+               uv_close((uv_handle_t *)handle, (uv_close_cb) free);
                return;
        }
 
@@ -165,13 +164,12 @@ static void tcp_accept(uv_stream_t *master, int status)
        uv_tcp_init(master->loop, client);
        client->data = buf_alloc();
        if (client->data == NULL) {
-               tcp_unbind_handle((uv_handle_t *)client);
                free(client);
                return;
        }
 
        if (uv_accept(master, (uv_stream_t*)client) != 0) {
-               tcp_unbind_handle((uv_handle_t *)client);
+               buf_free((uv_handle_t *)client);
                free(client);
                return;
        }
@@ -205,4 +203,5 @@ int tcp_bind(struct endpoint *ep, struct sockaddr *addr)
 void tcp_unbind(struct endpoint *ep)
 {
        tcp_unbind_handle((uv_handle_t *)&ep->tcp);
+       uv_close((uv_handle_t *)&ep->tcp, NULL);
 }