From b70c7331a9e21e6e9e4a8219a98cfe3f8c24e6d8 Mon Sep 17 00:00:00 2001 From: Jim Walker Date: Tue, 6 Oct 2020 09:27:32 +0100 Subject: [PATCH] Fix AddressSanitizer: stack-use-after-scope Move ThreadGate so it has a scope equal to the thread ==16055==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffceabf4548 at pc 0x00000520d834 bp 0x7fb4f0458520 sp 0x7fb4f0458518 READ of size 8 at 0x7ffceabf4548 thread T3 #0 0x520d833 in ThreadGate::isComplete(std::unique_lock const&) ../kv_engine/engines/ep/tests/module_tests/thread_gate.h:69 #1 0x520d833 in ThreadGate::threadUp()::{lambda()#1}::operator()() const ../kv_engine/engines/ep/tests/module_tests/thread_gate.h:45 #2 0x520d833 in void std::condition_variable::wait(std::unique_lock&, ThreadGate::threadUp()::{lambda()#1}) /usr/local/include/c++/7.3.0/condition_variable:98 #3 0x520d833 in ThreadGate::threadUp() ../kv_engine/engines/ep/tests/module_tests/thread_gate.h:45 #4 0x520d833 in resetThread(HdrHistogram&, ThreadGate&) ../kv_engine/engines/ep/tests/module_tests/hdrhistogram_test.cc:482 #5 0x5228687 in void std::__invoke_impl(std::__invoke_other, void (*&&)(HdrHistogram&, ThreadGate&), Hdr2sfMicroSecHistogram&, ThreadGate&) /usr/local/include/c++/7.3.0/bits/invoke.h:60 #6 0x5228687 in std::__invoke_result::type std::__invoke(void (*&&)(HdrHistogram&, ThreadGate&), Hdr2sfMicroSecHistogram&, ThreadGate&) /usr/local/include/c++/7.3.0/bits/invoke.h:95 #7 0x5228687 in decltype (__invoke((_S_declval<0ul>)(), (_S_declval<1ul>)(), (_S_declval<2ul>)())) std::thread::_Invoker >::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) /usr/local/include/c++/7.3.0/thread:234 #8 0x5228687 in std::thread::_Invoker >::operator()() /usr/local/include/c++/7.3.0/thread:243 #9 0x5228687 in std::thread::_State_impl > >::_M_run() /usr/local/include/c++/7.3.0/thread:186 #10 0x7fb4f66b295e in execute_native_thread_routine /tmp/deploy/objdir/../gcc-7.3.0/libstdc++-v3/src/c++11/thread.cc:83 #11 0x7fb4f51a76b9 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x76b9) #12 0x7fb4f4edd41c in clone (/lib/x86_64-linux-gnu/libc.so.6+0x10741c) Change-Id: Idb2dbb73d1a2e0b1beca570b38401009d3408906 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/137540 Reviewed-by: Richard de Mellow Tested-by: Build Bot --- engines/ep/tests/module_tests/hdrhistogram_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/ep/tests/module_tests/hdrhistogram_test.cc b/engines/ep/tests/module_tests/hdrhistogram_test.cc index c756a37721..2d5a44c6b4 100644 --- a/engines/ep/tests/module_tests/hdrhistogram_test.cc +++ b/engines/ep/tests/module_tests/hdrhistogram_test.cc @@ -501,6 +501,7 @@ TEST(HdrHistogramTest, ResetItoratorInfLoop) { } std::thread thread; + ThreadGate tg(2); { // Scope that holds read lock for iterator auto iter2 = histogram.getHistogramsIterator(); /** @@ -511,7 +512,6 @@ TEST(HdrHistogramTest, ResetItoratorInfLoop) { * and is about to try and get an exclusive lock before reading values * from the histogram. */ - ThreadGate tg(2); thread = std::thread(resetThread, std::ref(histogram), std::ref(tg)); tg.threadUp(); auto values = getAllValues(histogram, iter2);