From 6cee45014dd79d59914693afad9ca3b6af7f3cb3 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 4 May 2020 08:34:46 +0200 Subject: [PATCH] Return an error if we can't allocate the packet buffer during utcp_init(). --- utcp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; -- 2.39.5