]> granicus.if.org Git - sysstat/commitdiff
sadc: Don't reallocate structures if buffers are large enough
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 26 Sep 2020 07:24:28 +0000 (09:24 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 26 Sep 2020 07:24:28 +0000 (09:24 +0200)
When appending data to an existing file, don't reallocate buffers if
they are already large enough.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sadc.c

diff --git a/sadc.c b/sadc.c
index 43ce54974dc1becc8ee0a5da9fd89358809de487..7db7e93eb1e2765f61053cb023b4381613faace4 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -996,9 +996,11 @@ void open_ofile(int *ofd, char ofile[], int restart_mark)
                 * we need to reallocate.
                 */
                act[p]->nr2 = file_act[i].nr2;
+               if (act[p]->nr_ini > act[p]->nr_allocated) {
+                       act[p]->nr_allocated = act[p]->nr_ini;
+               }
                SREALLOC(act[p]->_buf0, void,
-                        (size_t) act[p]->msize * (size_t) act[p]->nr_ini * (size_t) act[p]->nr2);
-               act[p]->nr_allocated = act[p]->nr_ini;
+                        (size_t) act[p]->msize * (size_t) act[p]->nr_allocated * (size_t) act[p]->nr2);
 
                /* Save activity sequence */
                id_seq[i] = file_act[i].id;