X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdaemon%2Fmeta_data.c;h=b3f892a22061804ef0cfa79de2323dca3b55c7b0;hb=56cfc69d0a124c80036b73c2ef1c192706097faa;hp=8ddd47801ed7c9d6f9d80712ccf69443c0b49a21;hpb=16c20a278d3b08f4f4288e30e14d8aea2f648710;p=collectd.git diff --git a/src/daemon/meta_data.c b/src/daemon/meta_data.c index 8ddd4780..b3f892a2 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) @@ -117,6 +116,8 @@ static meta_entry_t *md_entry_clone_contents (const meta_entry_t *orig) /* {{{ * */ 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); @@ -290,15 +291,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); @@ -329,13 +328,14 @@ int meta_data_clone_merge (meta_data_t **dest, meta_data_t *orig) /* {{{ */ if (orig == NULL) return (0); - if(NULL == *dest) { + if (*dest == NULL) { *dest = meta_data_clone(orig); return(0); } pthread_mutex_lock (&orig->lock); - for(e=orig->head; NULL != e; e = e->next) { + for (e=orig->head; e != NULL; e = e->next) + { md_entry_insert_clone((*dest), e); } pthread_mutex_unlock (&orig->lock); @@ -348,7 +348,6 @@ void meta_data_destroy (meta_data_t *md) /* {{{ */ if (md == NULL) return; - pthread_mutex_destroy(&md->lock); md_entry_free (md->head); pthread_mutex_destroy (&md->lock); free (md); @@ -409,7 +408,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) { @@ -420,7 +419,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 */ @@ -599,7 +598,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;