Code

properly handle the case where RRDCACHED_ADDRESS is an empty string
[rrdtool.git] / src / rrd_client.c
index 47333df099a1495737e4fb4afdbee6986d6d93db..e7c227b8564338c1d74ab2f29c8bd033d459944d 100644 (file)
@@ -350,7 +350,8 @@ int rrdc_is_connected(const char *daemon_addr) /* {{{ */
      * but it is not specified in the current command.
      * Daemon is only implied in this case if set in ENV
      */
-    if (getenv(ENV_RRDCACHED_ADDRESS) != NULL)
+    char *addr = getenv(ENV_RRDCACHED_ADDRESS);
+    if (addr != NULL && strcmp(addr,"") != 0)
       return 1;
     else
       return 0;
@@ -502,6 +503,8 @@ static int rrdc_connect_network (const char *addr_orig) /* {{{ */
     break;
   } /* for (ai_ptr) */
 
+  freeaddrinfo(ai_res);
+
   return (status);
 } /* }}} int rrdc_connect_network */
 
@@ -509,11 +512,14 @@ int rrdc_connect (const char *addr) /* {{{ */
 {
   int status = 0;
 
-  if (addr == NULL)
+  if (addr == NULL) {
     addr = getenv (ENV_RRDCACHED_ADDRESS);
+  }
 
-  if (addr == NULL)
-    return 0;
+  if (addr == NULL || strcmp(addr,"") == 0 ) {
+    addr = NULL;
+    return 0;   
+  }
 
   pthread_mutex_lock(&lock);