diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2020-03-23 12:54:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-23 12:54:25 +0000 |
commit | 2e6b1f1e0409be6bdebeae5772dcf53851efd519 (patch) | |
tree | 2fe335e4cd7bcfb2fe09e16f444482e68039e79f /collectors/plugins.d | |
parent | 574707709db510daeba93511a3b3b4be96019916 (diff) |
Memory leak with labels on stream (#8460)
* cid353391: Fix memory leak
* cid353391: Avoid pointer to move out of allocated value
Diffstat (limited to 'collectors/plugins.d')
-rw-r--r-- | collectors/plugins.d/plugins_d.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/collectors/plugins.d/plugins_d.c b/collectors/plugins.d/plugins_d.c index 42c9202c36..ddccd939f2 100644 --- a/collectors/plugins.d/plugins_d.c +++ b/collectors/plugins.d/plugins_d.c @@ -627,10 +627,15 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int store = words[3]; else { store = callocz(PLUGINSD_LINE_MAX + 1, sizeof(char)); + size_t remaining = PLUGINSD_LINE_MAX; char *move = store; int i = 3; while (i < w) { size_t length = strlen(words[i]); + if ((length + 1) >= remaining) + break; + + remaining -= (length +1); memcpy(move, words[i], length); move += length; *move++ = ' '; @@ -642,6 +647,8 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int } new_labels = add_label_to_list(new_labels, words[1], store, strtol(words[2], NULL, 10)); + if (store != words[3]) + freez(store); } else if(likely(hash == OVERWRITE_HASH && !strcmp(s, PLUGINSD_KEYWORD_OVERWRITE))) { debug(D_PLUGINSD, "requested a OVERWITE a variable"); |