X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fethstat.c;h=dec14f3d148962df3b1aaf41eb1f50f0a7a5f92c;hb=31ee0e5282b59f89ac5c9bcaebb993450e45dba1;hp=ae1b68931d898830cca2a67e9aa2cc8034371803;hpb=fda68e239798cea197a225ed5325f5bb3c2e70de;p=collectd.git diff --git a/src/ethstat.c b/src/ethstat.c index ae1b6893..dec14f3d 100644 --- a/src/ethstat.c +++ b/src/ethstat.c @@ -66,13 +66,14 @@ static int ethstat_add_interface (const oconfig_item_t *ci) /* {{{ */ if (tmp == NULL) return (-1); interfaces = tmp; + interfaces[interfaces_num] = NULL; status = cf_util_get_string (ci, interfaces + interfaces_num); if (status != 0) return (status); interfaces_num++; - INFO("ethstat plugin: Registred interface %s", + INFO("ethstat plugin: Registered interface %s", interfaces[interfaces_num - 1]); return (0); @@ -82,6 +83,7 @@ static int ethstat_add_map (const oconfig_item_t *ci) /* {{{ */ { value_map_t *map; int status; + char *key; if ((ci->values_num < 2) || (ci->values_num > 3) @@ -95,16 +97,24 @@ static int ethstat_add_map (const oconfig_item_t *ci) /* {{{ */ return (-1); } + key = strdup (ci->values[0].value.string); + if (key == NULL) + { + ERROR ("ethstat plugin: strdup(3) failed."); + return (ENOMEM); + } + map = malloc (sizeof (*map)); if (map == NULL) { + sfree (key); ERROR ("ethstat plugin: malloc(3) failed."); return (ENOMEM); } memset (map, 0, sizeof (*map)); sstrncpy (map->type, ci->values[1].value.string, sizeof (map->type)); - if (ci->values_num == 2) + if (ci->values_num == 3) sstrncpy (map->type_instance, ci->values[2].value.string, sizeof (map->type_instance)); @@ -114,23 +124,24 @@ static int ethstat_add_map (const oconfig_item_t *ci) /* {{{ */ if (value_map == NULL) { sfree (map); + sfree (key); ERROR ("ethstat plugin: c_avl_create() failed."); return (-1); } } status = c_avl_insert (value_map, - /* key = */ ci->values[0].value.string, + /* key = */ key, /* value = */ map); if (status != 0) { - sfree (map); if (status > 0) - ERROR ("ethstat plugin: Multiple mappings for \"%s\".", - ci->values[0].value.string); + ERROR ("ethstat plugin: Multiple mappings for \"%s\".", key); else - ERROR ("ethstat plugin: c_avl_insert(\"%s\") failed.", - ci->values[0].value.string); + ERROR ("ethstat plugin: c_avl_insert(\"%s\") failed.", key); + + sfree (map); + sfree (key); return (-1); } @@ -327,10 +338,31 @@ static int ethstat_read(void) return 0; } +static int ethstat_shutdown (void) +{ + void *key = NULL; + void *value = NULL; + + if (value_map == NULL) + return (0); + + while (c_avl_pick (value_map, &key, &value) == 0) + { + sfree (key); + sfree (value); + } + + c_avl_destroy (value_map); + value_map = NULL; + + return (0); +} + void module_register (void) { plugin_register_complex_config ("ethstat", ethstat_config); plugin_register_read ("ethstat", ethstat_read); + plugin_register_shutdown ("ethstat", ethstat_shutdown); } /* vim: set sw=2 sts=2 et fdm=marker : */