write_graphite plugin: Don't allocate {Pre,Post}fix if unspecified.
authorFlorian Forster <octo@collectd.org>
Thu, 2 Feb 2012 16:43:28 +0000 (17:43 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 2 Feb 2012 17:18:06 +0000 (18:18 +0100)
Just leave them at NULL and catch this condition in wg_format_name().

src/write_graphite.c

index c658e20..827ec38 100644 (file)
@@ -377,6 +377,12 @@ static int wg_format_name (char *ret, int ret_len,
     assert (plugin != NULL);
     assert (type != NULL);
 
+    if (prefix == NULL)
+        prefix = "";
+
+    if (postfix == NULL)
+        postfix = "";
+
     if ((n_hostname = malloc(strlen(hostname)+1)) == NULL)
     {
         ERROR ("Unable to allocate memory for normalized hostname buffer");
@@ -679,24 +685,6 @@ static int wg_config_carbon (oconfig_item_t *ci)
         }
     }
 
-    if (cb->prefix == NULL) {
-        if ((cb->prefix = malloc((int)sizeof(char))) == NULL)
-        {
-            ERROR ("Unable to allocate memory for hostname prefix buffer");
-            return (-1);
-        }
-        cb->prefix[0] = '\0';
-    }
-
-    if (cb->postfix == NULL) {
-        if ((cb->postfix = malloc((int)sizeof(char))) == NULL)
-        {
-            ERROR ("Unable to allocate memory for hostname postfix buffer");
-            return (-1);
-        }
-        cb->postfix[0] = '\0';
-    }
-
     DEBUG ("write_graphite: Registering write callback to carbon agent %s:%s",
             cb->node ? cb->node : WG_DEFAULT_NODE,
             cb->service ? cb->service : WG_DEFAULT_SERVICE);