]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Change the semantic of `label_set_clone`.
authorFlorian Forster <octo@collectd.org>
Wed, 13 Dec 2023 14:35:23 +0000 (15:35 +0100)
committerFlorian Forster <octo@collectd.org>
Wed, 13 Dec 2023 21:39:11 +0000 (22:39 +0100)
It checks to ensure that `dest` is empty and returns `EINVAL` otherwise.

src/daemon/metric.c
src/daemon/metric.h

index 55edc7a7d89708ae2b89a0b8489a34e657689469..d273863d7b2f1df2223263222b5912bc85a9093e 100644 (file)
@@ -214,6 +214,10 @@ void label_set_reset(label_set_t *labels) {
 }
 
 int label_set_clone(label_set_t *dest, label_set_t src) {
+  if (dest == NULL || dest->num != 0) {
+    return EINVAL;
+  }
+
   if (src.num == 0) {
     return 0;
   }
index a91f596f1d4226a507b2dfaa3d77e5d501633b2e..35fdf6dad7831bb726788839671a96ad95759db3 100644 (file)
@@ -70,9 +70,9 @@ typedef struct {
   size_t num;
 } label_set_t;
 
-/* label_set_clone copies all the labels in src into dest. If dest contains
- * any labels prior to calling label_set_clone, the associated memory is
- * leaked. */
+/* label_set_clone copies all the labels in src into dest. dest must be an empty
+ * label set, i.e. it must not contain any prior labels, otherwise EINVAL is
+ * returned. */
 int label_set_clone(label_set_t *dest, label_set_t src);
 
 /* label_set_add adds a label to the label set. If a label with name already