Skip to content

Commit

Permalink
cdp: fix three coverity errors (ressource leaks and error checks)
Browse files Browse the repository at this point in the history
- fix an ressource leak related to library call getaddrinfo
- add missing error checks for setsockopts and fcntl calls

(cherry picked from commit 967a716)
  • Loading branch information
henningw committed Dec 30, 2018
1 parent 5d73871 commit 977057f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/modules/cdp/receiver.c
Expand Up @@ -839,6 +839,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;
Expand Down Expand Up @@ -930,10 +931,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)){
Expand All @@ -943,10 +955,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;
}

Expand Down

0 comments on commit 977057f

Please sign in to comment.