From 5197cebb5fbdc6244f5a99de96fcedd72777f870 Mon Sep 17 00:00:00 2001 From: Leonardo Alminana Date: Tue, 26 Sep 2023 10:15:14 +0200 Subject: [PATCH] tests: internal: stream_processor: fixed memory leak Signed-off-by: Leonardo Alminana --- tests/internal/stream_processor.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/internal/stream_processor.c b/tests/internal/stream_processor.c index c9e59f50407..6e9b631713c 100644 --- a/tests/internal/stream_processor.c +++ b/tests/internal/stream_processor.c @@ -517,6 +517,13 @@ static void test_window() usleep(800000); } + if (out_buf.buffer != NULL) { + flb_free(out_buf.buffer); + + out_buf.buffer = NULL; + out_buf.size = 0; + } + flb_sp_fd_event_test(task->window.fd, task, &out_buf); flb_info("[sp test] id=%i, SQL => '%s'", check->id, check->exec); @@ -560,13 +567,26 @@ static void test_window() /* Hopping event */ if ((t + 1) % check->window_hop_sec == 0) { + if (out_buf.buffer != NULL) { + flb_free(out_buf.buffer); + + out_buf.buffer = NULL; + out_buf.size = 0; + } + flb_sp_fd_event_test(task->window.fd_hop, task, &out_buf); } /* Window event */ if ((t + 1) % check->window_size_sec == 0 || (t + 1 > check->window_size_sec && (t + 1 - check->window_size_sec) % check->window_hop_sec == 0)) { - flb_free(out_buf.buffer); + if (out_buf.buffer != NULL) { + flb_free(out_buf.buffer); + + out_buf.buffer = NULL; + out_buf.size = 0; + } + flb_sp_fd_event_test(task->window.fd, task, &out_buf); } flb_free(data_buf.buffer);