X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmatch_value.c;h=3b269c8c9c061ff77a7ddf7b7bc9a53af3c58dc4;hb=71bbf854d3e6f8c6d6c3582527263bb01a3a7e04;hp=4d49984f618173b48323634a3ed34a1b85cde048;hpb=dc2eb041159b967838a2eb658cb256bc846c5264;p=collectd.git diff --git a/src/match_value.c b/src/match_value.c index 4d49984f..3b269c8c 100644 --- a/src/match_value.c +++ b/src/match_value.c @@ -58,8 +58,8 @@ struct mv_match_s */ static void mv_free_match (mv_match_t *m) /* {{{ */ { - int i; - + size_t i; + if (m == NULL) return; @@ -69,7 +69,7 @@ static void mv_free_match (mv_match_t *m) /* {{{ */ free(m->data_sources[i]); free(m->data_sources); } - + free (m); } /* }}} void mv_free_match */ @@ -129,7 +129,7 @@ static int mv_config_add_data_source (mv_match_t *m, /* {{{ */ /* Allocate space for the char pointers */ new_data_sources_num = m->data_sources_num + ((size_t) ci->values_num); - temp = (char **) realloc (m->data_sources, + temp = realloc (m->data_sources, new_data_sources_num * sizeof (char *)); if (temp == NULL) { @@ -200,13 +200,12 @@ static int mv_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - m = (mv_match_t *) malloc (sizeof (*m)); + m = calloc (1, sizeof (*m)); if (m == NULL) { - ERROR ("mv_create: malloc failed."); + ERROR ("mv_create: calloc failed."); return (-ENOMEM); } - memset (m, 0, sizeof (*m)); m->min = NAN; m->max = NAN; @@ -277,7 +276,7 @@ static int mv_match (const data_set_t *ds, const value_list_t *vl, /* {{{ */ mv_match_t *m; gauge_t *values; int status; - int i; + size_t i; if ((user_data == NULL) || (*user_data == NULL)) return (-1); @@ -336,7 +335,7 @@ static int mv_match (const data_set_t *ds, const value_list_t *vl, /* {{{ */ if (m->satisfy == SATISFY_ANY) break; } - else if (value_matches == 0) + else { status = FC_MATCH_NO_MATCH; if (m->satisfy == SATISFY_ALL) @@ -350,9 +349,8 @@ static int mv_match (const data_set_t *ds, const value_list_t *vl, /* {{{ */ void module_register (void) { - match_proc_t mproc; + match_proc_t mproc = { 0 }; - memset (&mproc, 0, sizeof (mproc)); mproc.create = mv_create; mproc.destroy = mv_destroy; mproc.match = mv_match;