From 4a3f26b2cf540825313cb25bcdce5a18b74ca95f Mon Sep 17 00:00:00 2001 From: Dong Anyuan <donganyuan@cn.fujitsu.com> Date: Thu, 20 Jun 2019 14:01:05 +0900 Subject: [PATCH] Fix Coverity Scan CID 340228 (Handle variable s going out of scope leaks the handle.) --- openair2/UTIL/ASYNC_IF/socket_link.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openair2/UTIL/ASYNC_IF/socket_link.c b/openair2/UTIL/ASYNC_IF/socket_link.c index 5717624930..51c5511675 100644 --- a/openair2/UTIL/ASYNC_IF/socket_link.c +++ b/openair2/UTIL/ASYNC_IF/socket_link.c @@ -218,6 +218,7 @@ error: socket_link_t *new_link_udp_client(const char *server, int port){ + int s = -1; socket_link_t *ret = NULL; ret = calloc(1, sizeof(socket_link_t)); if (ret == NULL) { @@ -227,7 +228,6 @@ socket_link_t *new_link_udp_client(const char *server, int port){ ret->socket_fd = -1; struct sockaddr_in si_other; - int s; socklen_t slen = sizeof(si_other); if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){ @@ -254,8 +254,12 @@ socket_link_t *new_link_udp_client(const char *server, int port){ return ret; error: if (ret != NULL) { - close(ret->socket_fd); free(ret); + ret = NULL; + } + if (s != -1) { + close(s); + s = -1; } LOG_E(MAC, "ERROR in new_link_udp_client (see above), returning NULL\n"); return NULL; -- GitLab