From: Florian Forster Date: Fri, 12 May 2017 11:05:37 +0000 (+0200) Subject: write_prometheus plugin: Fix incorrect use of realloc(). X-Git-Tag: collectd-5.7.2~7^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9a1a776fd790728f1158e65259dbecc8c43e34c9;p=collectd.git write_prometheus plugin: Fix incorrect use of realloc(). Calling realloc(ptr, 0) is undefined. Call free() explicitly. --- diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 6b77712e..de1c389c 100644 --- a/src/write_prometheus.c +++ b/src/write_prometheus.c @@ -546,9 +546,14 @@ metric_family_delete_metric(Io__Prometheus__Client__MetricFamily *fam, ((fam->n_metric - 1) - i) * sizeof(fam->metric[i])); fam->n_metric--; + if (fam->n_metric == 0) { + sfree(fam->metric); + return 0; + } + Io__Prometheus__Client__Metric **tmp = realloc(fam->metric, fam->n_metric * sizeof(*fam->metric)); - if ((tmp != NULL) || (fam->n_metric == 0)) + if (tmp != NULL) fam->metric = tmp; return 0;