Skip to content

Commit

Permalink
Do not allocate unused Intervals lined-list to solve memory-leak (by …
Browse files Browse the repository at this point in the history
…design)
  • Loading branch information
davidBar-On committed Dec 20, 2024
1 parent e4cb673 commit a864caa
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a864caa

Please sign in to comment.