From: Florian Forster Date: Thu, 2 Feb 2012 16:43:28 +0000 (+0100) Subject: write_graphite plugin: Don't allocate {Pre,Post}fix if unspecified. X-Git-Tag: collectd-5.1.0~35^2~25^2 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=cbe5d0b3deec5978a5b0c61371d5c87b9285a0ae write_graphite plugin: Don't allocate {Pre,Post}fix if unspecified. Just leave them at NULL and catch this condition in wg_format_name(). --- 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);