Fix Coverity Scan CID 340228 (Handle variable s going out of scope leaks the handle.)

This commit is contained in:
Dong Anyuan
2019-06-20 14:01:05 +09:00
parent f6765e0633
commit 4a3f26b2cf
+6 -2
View File
@@ -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;