From: Guus Sliepen Date: Mon, 4 May 2020 06:34:46 +0000 (+0200) Subject: Return an error if we can't allocate the packet buffer during utcp_init(). X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=6cee45014dd79d59914693afad9ca3b6af7f3cb3;p=utcp Return an error if we can't allocate the packet buffer during utcp_init(). --- diff --git a/utcp.c b/utcp.c index 20d86c2..5eca4d3 100644 --- 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;