Skip to content

Commit

Permalink
statsd: simplified error handling inside statsd_connect()
Browse files Browse the repository at this point in the history
(cherry picked from commit f75eba6)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent 99340e1 commit b87bccd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/modules/statsd/lib_statsd.c
Expand Up @@ -29,25 +29,24 @@ bool statsd_connect(void){
rc = getaddrinfo(
statsd_connection.ip, statsd_connection.port,
NULL, &serverAddr);
if (rc != 0)
if (rc != 0 || serverAddr == NULL)
{
LM_ERR(
"Statsd: could not initiate server information (%s)\n",
LM_ERR("Statsd: could not initiate server information (%s)\n",
gai_strerror(rc));
if(serverAddr) freeaddrinfo(serverAddr);
if(serverAddr) freeaddrinfo(serverAddr);
return false;
}

statsd_connection.sock = socket(serverAddr->ai_family, SOCK_DGRAM, IPPROTO_UDP);
if (statsd_connection.sock < 0 ){
LM_ERR("Statsd: could not create a socket for statsd connection\n");
if(serverAddr) freeaddrinfo(serverAddr);
freeaddrinfo(serverAddr);
return false;
}

rc = connect(
statsd_connection.sock, serverAddr->ai_addr, serverAddr->ai_addrlen);
freeaddrinfo(serverAddr);
rc = connect(statsd_connection.sock, serverAddr->ai_addr,
serverAddr->ai_addrlen);
freeaddrinfo(serverAddr);
if (rc < 0){
LM_ERR("Statsd: could not initiate a connect to statsd\n");
return false;
Expand Down

0 comments on commit b87bccd

Please sign in to comment.