From: Florian Forster Date: Tue, 2 Sep 2014 17:50:47 +0000 (+0200) Subject: src/meta_data.c: If the meta_data_t is empty, avoid calling malloc(0). X-Git-Tag: collectd-5.3.2~45 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=670dd12b750843cf83ac3cf052b4c2d8b635c212;p=collectd.git src/meta_data.c: If the meta_data_t is empty, avoid calling malloc(0). --- diff --git a/src/meta_data.c b/src/meta_data.c index ea98ba94..1b587352 100644 --- a/src/meta_data.c +++ b/src/meta_data.c @@ -313,7 +313,13 @@ int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */ for (e = md->head; e != NULL; e = e->next) ++count; - *toc = malloc(count * sizeof(**toc)); + if (count == 0) + { + pthread_mutex_unlock (&md->lock); + return (count); + } + + *toc = calloc(count, sizeof(**toc)); for (e = md->head; e != NULL; e = e->next) (*toc)[i++] = strdup(e->key);