X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fwrite_prometheus.c;h=14d78bb18dbc469fa39918f8aa801a31c53da7e8;hb=57b9e83320b35d4dbd1312db5fbf33ddf8ecd989;hp=991415ef08713ddb7939e63fd7d5d196a3d35981;hpb=3fb6fe5776c14f41879249f4147c0b8924b39cc1;p=collectd.git diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 991415ef..14d78bb1 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; @@ -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) { @@ -868,5 +875,3 @@ void module_register() { /* user data = */ NULL); plugin_register_shutdown("write_prometheus", prom_shutdown); } - -/* vim: set sw=2 sts=2 et fdm=marker : */