]> git.meshlink.io Git - utcp/commitdiff
Return an error if we can't allocate the packet buffer during utcp_init().
authorGuus Sliepen <guus@sliepen.org>
Mon, 4 May 2020 06:34:46 +0000 (08:34 +0200)
committerGuus Sliepen <guus@sliepen.org>
Mon, 4 May 2020 06:34:46 +0000 (08:34 +0200)
utcp.c

diff --git a/utcp.c b/utcp.c
index 20d86c27c6135e8b35e78db94f7fbedfbec747b5..5eca4d3897a82eec6bbc1bca6de33c324fb73daa 100644 (file)
--- a/utcp.c
+++ b/utcp.c
@@ -2169,6 +2169,13 @@ struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_
                return NULL;
        }
 
+       utcp_set_mtu(utcp, DEFAULT_MTU);
+
+       if(!utcp->pkt) {
+               free(utcp);
+               return NULL;
+       }
+
        if(!CLOCK_GRANULARITY) {
                struct timespec res;
                clock_getres(UTCP_CLOCK, &res);
@@ -2179,7 +2186,6 @@ struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_
        utcp->pre_accept = pre_accept;
        utcp->send = send;
        utcp->priv = priv;
-       utcp_set_mtu(utcp, DEFAULT_MTU);
        utcp->timeout = DEFAULT_USER_TIMEOUT; // sec
 
        return utcp;