From cbe5d0b3deec5978a5b0c61371d5c87b9285a0ae Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 2 Feb 2012 17:43:28 +0100 Subject: [PATCH] write_graphite plugin: Don't allocate {Pre,Post}fix if unspecified. Just leave them at NULL and catch this condition in wg_format_name(). --- src/write_graphite.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/write_graphite.c b/src/write_graphite.c index c658e207..827ec388 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -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); -- 2.30.2