]> git.meshlink.io Git - utcp/commitdiff
Fix a memory leak on invalid invocation of utcp_init().
authorGuus Sliepen <guus@meshlink.io>
Sun, 18 Oct 2015 11:54:14 +0000 (13:54 +0200)
committerGuus Sliepen <guus@sliepen.org>
Sun, 2 Jul 2017 10:03:28 +0000 (12:03 +0200)
utcp.c

diff --git a/utcp.c b/utcp.c
index 2b2db972163ceb2427b817f2bc70bc69d84889df..ad19982ba95afdb613eb780e6ac8d8eff6511ee3 100644 (file)
--- a/utcp.c
+++ b/utcp.c
@@ -1309,15 +1309,15 @@ bool utcp_is_active(struct utcp *utcp) {
 }
 
 struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_send_t send, void *priv) {
-       struct utcp *utcp = calloc(1, sizeof *utcp);
-       if(!utcp)
-               return NULL;
-
        if(!send) {
                errno = EFAULT;
                return NULL;
        }
 
+       struct utcp *utcp = calloc(1, sizeof *utcp);
+       if(!utcp)
+               return NULL;
+
        utcp->accept = accept;
        utcp->pre_accept = pre_accept;
        utcp->send = send;