From a864caa61e0db1ddba9d3abecc3c6cfd12c6d2a1 Mon Sep 17 00:00:00 2001 From: DavidBar-On Date: Fri, 20 Dec 2024 16:47:43 +0200 Subject: [PATCH] Do not allocate unused Intervals lined-list to solve memory-leak (by design) --- src/iperf_api.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/iperf_api.c b/src/iperf_api.c index fa06dc830..3a8ef7255 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -2844,6 +2844,14 @@ add_to_interval_list(struct iperf_stream_result * rp, struct iperf_interval_resu { struct iperf_interval_results *irp; + /* Only the last interval result is needed, so removing last old entry to reduce memory consupmtion */ + if (!TAILQ_EMPTY(&rp->interval_results) && + (irp = TAILQ_LAST(&rp->interval_results, irlisthead)) != NULL + ) { + TAILQ_REMOVE(&rp->interval_results, irp, irlistentries); + free(irp); + } + irp = (struct iperf_interval_results *) malloc(sizeof(struct iperf_interval_results)); memcpy(irp, new, sizeof(struct iperf_interval_results)); TAILQ_INSERT_TAIL(&rp->interval_results, irp, irlistentries);