From 20a7434400053998709109592ef17aa8c87a35ab Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 14 Nov 2007 11:37:00 +0100 Subject: [PATCH] rrdtool plugin: Fix a memory leak.. ..in a VERY uncommon/rare case. --- src/rrdtool.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rrdtool.c b/src/rrdtool.c index fbd83602..79331bf7 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -735,9 +735,9 @@ static void rrd_cache_flush (int timeout) } else /* ancient and no values -> waste of memory */ { - keys = (char **) realloc ((void *) keys, + char **tmp = (char **) realloc ((void *) keys, (keys_num + 1) * sizeof (char *)); - if (keys == NULL) + if (tmp == NULL) { char errbuf[1024]; ERROR ("rrdtool plugin: " @@ -745,8 +745,10 @@ static void rrd_cache_flush (int timeout) sstrerror (errno, errbuf, sizeof (errbuf))); c_avl_iterator_destroy (iter); + sfree (keys); return; } + keys = tmp; keys[keys_num] = key; keys_num++; } @@ -769,7 +771,7 @@ static void rrd_cache_flush (int timeout) keys[i] = NULL; } /* for (i = 0..keys_num) */ - free (keys); + sfree (keys); cache_flush_last = now; } /* void rrd_cache_flush */ -- 2.30.2