Code

Merge branch 'collectd-5.2' into collectd-5.3
[collectd.git] / src / write_graphite.c
index 949a8425178f700b952787f15bc0426f4f6d7299..99c6f4d80a91a669ee0ac86f0bfe0620de6bb13f 100644 (file)
@@ -222,7 +222,6 @@ static int wg_callback_init (struct wg_callback *cb)
                 "write_graphite plugin: Connecting to %s:%s failed. "
                 "The last error was: %s", node, service,
                 sstrerror (errno, errbuf, sizeof (errbuf)));
-        close (cb->sock_fd);
         return (-1);
     }
     else
@@ -250,8 +249,11 @@ static void wg_callback_free (void *data)
 
     wg_flush_nolock (/* timeout = */ 0, cb);
 
-    close(cb->sock_fd);
-    cb->sock_fd = -1;
+    if (cb->sock_fd >= 0)
+    {
+        close (cb->sock_fd);
+        cb->sock_fd = -1;
+    }
 
     sfree(cb->name);
     sfree(cb->node);
@@ -367,12 +369,9 @@ static int wg_write_messages (const data_set_t *ds, const value_list_t *vl,
         return (status);
 
     /* Send the message to graphite */
-    wg_send_message (buffer, cb);
-    if (status != 0)
-    {
-        /* An error message has already been printed. */
+    status = wg_send_message (buffer, cb);
+    if (status != 0) /* error message has been printed already. */
         return (status);
-    }
 
     return (0);
 } /* int wg_write_messages */