Module: kamailio
Branch: master
Commit: 967a71687aa63a253d495ba49351ae916713a452
URL:
https://github.com/kamailio/kamailio/commit/967a71687aa63a253d495ba49351ae9…
Author: Henning Westerholt <hw(a)kamailio.org>
Committer: Henning Westerholt <hw(a)kamailio.org>
Date: 2018-12-30T00:42:31+01:00
cdp: fix three coverity errors (ressource leaks and error checks)
- fix an ressource leak related to library call getaddrinfo
- add missing error checks for setsockopts and fcntl calls
---
Modified: src/modules/cdp/receiver.c
---
Diff:
https://github.com/kamailio/kamailio/commit/967a71687aa63a253d495ba49351ae9…
Patch:
https://github.com/kamailio/kamailio/commit/967a71687aa63a253d495ba49351ae9…
---
diff --git a/src/modules/cdp/receiver.c b/src/modules/cdp/receiver.c
index 6257d15362..c33554457a 100644
--- a/src/modules/cdp/receiver.c
+++ b/src/modules/cdp/receiver.c
@@ -844,6 +844,7 @@ int receive_loop(peer *original_peer)
int peer_connect(peer *p)
{
int sock;
+ int tmp = 0;
unsigned int option = 1;
struct addrinfo *ainfo=0,*res=0,*sainfo=0,hints;
@@ -935,10 +936,21 @@ int peer_connect(peer *p)
}
x=fcntl(sock,F_GETFL,0);
- fcntl(sock,F_SETFL,x & (~O_NONBLOCK));
+ if (x == -1) {
+ LM_ERR("error during first fcntl operation\n");
+ goto error;
+ }
+ tmp = fcntl(sock,F_SETFL,x & (~O_NONBLOCK));
+ if (tmp == -1) {
+ LM_ERR("error during second fcntl operation\n");
+ goto error;
+ }
+ }
+ tmp = setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&option,sizeof(option));
+ if (tmp == -1) {
+ LM_ERR("could not set socket options\n");
+ goto error;
}
- setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&option,sizeof(option));
-
LM_INFO("peer_connect(): Peer %.*s:%d
connected\n",p->fqdn.len,p->fqdn.s,p->port);
if (!send_fd(p->fd_exchange_pipe,sock,p)){
@@ -948,10 +960,12 @@ int peer_connect(peer *p)
}
if (res) freeaddrinfo(res);
+ if (sainfo) freeaddrinfo(sainfo);
return sock;
}
error:
if (res) freeaddrinfo(res);
+ if (sainfo) freeaddrinfo(sainfo);
return -1;
}