浏览代码

statsd: free srv variable in error handling

Daniel-Constantin Mierla 9 年之前
父节点
当前提交
f6f6c7f55d
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      modules/statsd/lib_statsd.c

+ 3 - 1
modules/statsd/lib_statsd.c

@@ -19,7 +19,7 @@ static StatsConnection statsd_connection = {
 
 bool statsd_connect(void){
 
-    struct addrinfo *serverAddr;
+    struct addrinfo *serverAddr = NULL;
     int rc;
 
     if (statsd_connection.sock > 0){
@@ -34,12 +34,14 @@ bool statsd_connect(void){
         LM_ERR(
             "Statsd: could not initiate server information (%s)\n",
             gai_strerror(rc));
+		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);
         return false;
     }