From f879b511bf2d8ebf0a3c0bbe5c059c95fc74e96b Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Wed, 23 Jun 2021 20:06:33 +0200 Subject: [PATCH] hooks: fix memory leak caused by hooks whic skip samples --- lib/hook_list.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/hook_list.cpp b/lib/hook_list.cpp index 0296c610b..99fa72ad1 100644 --- a/lib/hook_list.cpp +++ b/lib/hook_list.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include using namespace villas; @@ -143,7 +144,7 @@ int hook_list_process(struct vlist *hs, struct sample * smps[], unsigned cnt) return cnt; for (current = 0; current < cnt; current++) { - sample *smp = smps[current]; + struct sample *smp = smps[current]; for (size_t i = 0; i < vlist_length(hs); i++) { Hook *h = (Hook *) vlist_at(hs, i); @@ -165,11 +166,12 @@ int hook_list_process(struct vlist *hs, struct sample * smps[], unsigned cnt) } } - smps[processed++] = smp; +stop: SWAP(smps[processed], smps[current]); + processed++; skip: {} } -stop: return processed; + return processed; } void hook_list_periodic(struct vlist *hs)