Memory leak with labels on stream (#8460)
* cid353391: Fix memory leak * cid353391: Avoid pointer to move out of allocated value
thiagoftsm committed
Mar 23, 2020 at 12:54 UTC
2e6b1f1e0409be6bdebeae5772dcf53851efd519
1 file changed
+7
collectors/plugins.d/plugins_d.c
+7
@@ -627,10 +627,15 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
627
store = words[3];
628
else {
629
store = callocz(PLUGINSD_LINE_MAX + 1, sizeof(char));
630
+ size_t remaining = PLUGINSD_LINE_MAX;
631
char *move = store;
632
int i = 3;
633
while (i < w) {
634
size_t length = strlen(words[i]);
635
+ if ((length + 1) >= remaining)
636
+ break;
637
+
638
+ remaining -= (length +1);
639
memcpy(move, words[i], length);
640
move += length;
641
*move++ = ' ';
@@ -642,6 +647,8 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
647
}
648
649
new_labels = add_label_to_list(new_labels, words[1], store, strtol(words[2], NULL, 10));
650
+ if (store != words[3])
651
+ freez(store);
652
}
653
else if(likely(hash == OVERWRITE_HASH && !strcmp(s, PLUGINSD_KEYWORD_OVERWRITE))) {
654
debug(D_PLUGINSD, "requested a OVERWITE a variable");