]> git.meshlink.io Git - utcp/commitdiff
Fix a memory leak.
authorGuus Sliepen <guus@meshlink.io>
Mon, 19 Oct 2015 18:46:27 +0000 (20:46 +0200)
committerGuus Sliepen <guus@sliepen.org>
Sun, 2 Jul 2017 10:04:22 +0000 (12:04 +0200)
The receive buffer was never freed.

utcp.c

diff --git a/utcp.c b/utcp.c
index 5ba4eaade2f585d6ad39a702cadef13c64b01e2a..c93d4bb35bc476717fa9233b7c7a43e73d546a77 100644 (file)
--- a/utcp.c
+++ b/utcp.c
@@ -273,6 +273,7 @@ static void free_connection(struct utcp_connection *c) {
        memmove(cp, cp + 1, (utcp->nconnections - i - 1) * sizeof *cp);
        utcp->nconnections--;
 
+       buffer_exit(&c->rcvbuf);
        buffer_exit(&c->sndbuf);
        free(c);
 }
@@ -318,6 +319,7 @@ static struct utcp_connection *allocate_connection(struct utcp *utcp, uint16_t s
        }
 
        if(!buffer_init(&c->rcvbuf, DEFAULT_RCVBUFSIZE, DEFAULT_MAXRCVBUFSIZE)) {
+               buffer_exit(&c->sndbuf);
                free(c);
                return NULL;
        }
@@ -1416,6 +1418,7 @@ void utcp_exit(struct utcp *utcp) {
        for(int i = 0; i < utcp->nconnections; i++) {
                if(!utcp->connections[i]->reapable)
                        debug("Warning, freeing unclosed connection %p\n", utcp->connections[i]);
+               buffer_exit(&utcp->connections[i]->rcvbuf);
                buffer_exit(&utcp->connections[i]->sndbuf);
                free(utcp->connections[i]);
        }