X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fmeta_data.c;h=f87e35e41c78607d1eb3609688d6982c02d341c8;hb=09c12e0e1e0ef340a7074146684650ed54cba64d;hp=4e46ed53355ff30346a239d3d8bcb3d3c5511e34;hpb=4c30f47794046ec7c8dfb5e1d41d03633032bac7;p=collectd.git diff --git a/src/daemon/meta_data.c b/src/daemon/meta_data.c index 4e46ed53..f87e35e4 100644 --- a/src/daemon/meta_data.c +++ b/src/daemon/meta_data.c @@ -71,7 +71,7 @@ static char *md_strdup (const char *orig) /* {{{ */ return (NULL); sz = strlen (orig) + 1; - dest = (char *) malloc (sz); + dest = malloc (sz); if (dest == NULL) return (NULL); @@ -84,13 +84,12 @@ static meta_entry_t *md_entry_alloc (const char *key) /* {{{ */ { meta_entry_t *e; - e = (meta_entry_t *) malloc (sizeof (*e)); + e = calloc (1, sizeof (*e)); if (e == NULL) { - ERROR ("md_entry_alloc: malloc failed."); + ERROR ("md_entry_alloc: calloc failed."); return (NULL); } - memset (e, 0, sizeof (*e)); e->key = md_strdup (key); if (e->key == NULL) @@ -114,6 +113,8 @@ static meta_entry_t *md_entry_clone (const meta_entry_t *orig) /* {{{ */ return (NULL); copy = md_entry_alloc (orig->key); + if (copy == NULL) + return (NULL); copy->type = orig->type; if (copy->type == MD_TYPE_STRING) copy->value.mv_string = strdup (orig->value.mv_string); @@ -218,15 +219,13 @@ meta_data_t *meta_data_create (void) /* {{{ */ { meta_data_t *md; - md = (meta_data_t *) malloc (sizeof (*md)); + md = calloc (1, sizeof (*md)); if (md == NULL) { - ERROR ("meta_data_create: malloc failed."); + ERROR ("meta_data_create: calloc failed."); return (NULL); } - memset (md, 0, sizeof (*md)); - md->head = NULL; pthread_mutex_init (&md->lock, /* attr = */ NULL); return (md); @@ -315,7 +314,7 @@ int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */ pthread_mutex_lock (&md->lock); for (e = md->head; e != NULL; e = e->next) - ++count; + ++count; if (count == 0) { @@ -326,7 +325,7 @@ int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */ *toc = calloc(count, sizeof(**toc)); for (e = md->head; e != NULL; e = e->next) (*toc)[i++] = strdup(e->key); - + pthread_mutex_unlock (&md->lock); return count; } /* }}} int meta_data_toc */ @@ -505,7 +504,7 @@ int meta_data_get_string (meta_data_t *md, /* {{{ */ ERROR ("meta_data_get_string: md_strdup failed."); return (-ENOMEM); } - + pthread_mutex_unlock (&md->lock); *value = temp;