From a8c4854f60d72d083bd34b34a9ccccc7353d052c Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 19 Dec 2023 10:54:11 +0100 Subject: various TSAN/ASAN/LeakAnalyzer fixes (#622) * fix JobQueue test threading issue. The inner job queued with `QueueJob` would reference `I` from inside the captured closure which would subsequently disappear * made sure application exit is thread safe * don't try to access string data out of bounds * keep-alive flag is accessed from multiple threads * fix memory leaks in Zen upstream client code * TSAN fixes for Event --- src/zencore/jobqueue.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/zencore/jobqueue.cpp') diff --git a/src/zencore/jobqueue.cpp b/src/zencore/jobqueue.cpp index 1755b9fe9..4bcc5c885 100644 --- a/src/zencore/jobqueue.cpp +++ b/src/zencore/jobqueue.cpp @@ -422,8 +422,10 @@ TEST_CASE("JobQueue") { JobsLatch.AddCount(1); Pool.ScheduleWork([&Queue, &JobsLatch, I]() { - auto _ = MakeGuard([&JobsLatch]() { JobsLatch.CountDown(); }); - auto Id = Queue->QueueJob(fmt::format("busy {}", I), [&](JobContext& Context) { + auto _ = MakeGuard([&JobsLatch]() { JobsLatch.CountDown(); }); + JobsLatch.AddCount(1); + auto Id = Queue->QueueJob(fmt::format("busy {}", I), [&JobsLatch, I](JobContext& Context) { + auto $ = MakeGuard([&JobsLatch]() { JobsLatch.CountDown(); }); if (Context.IsCancelled()) { return; @@ -523,7 +525,6 @@ TEST_CASE("JobQueue") } JobsLatch.Wait(); } - #endif } // namespace zen -- cgit v1.2.3