X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_prometheus.c;h=526499849c2f27a5040f8d8b7febc00a107c9494;hb=5ff74d56067ac64db801df5184eb8b97f4b2b645;hp=6dee98abc4ec2b994f522a07add1faf25793be1b;hpb=b9f877bc827ea4c0097682fc87cc5bcfd0000807;p=collectd.git diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 6dee98ab..52649984 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; @@ -594,8 +599,8 @@ static int metric_family_update(Io__Prometheus__Client__MetricFamily *fam, if (m == NULL) return -1; - return metric_update(m, vl->values[ds_index], ds->ds[ds_index].type, vl->time, - vl->interval); + return metric_update(m, vl->values[ds_index], ds->ds[ds_index].type, + vl->time, vl->interval); } /* metric_family_destroy frees the memory used by a metric family. */ @@ -694,8 +699,10 @@ metric_family_get(data_set_t const *ds, value_list_t const *vl, size_t ds_index, return fam; } - if (!allocate) + if (!allocate) { + sfree(name); return NULL; + } fam = metric_family_create(name, ds, vl, ds_index); if (fam == NULL) {