Skip to content

Commit

Permalink
Fix AddressSanitizer: stack-use-after-scope
Browse files Browse the repository at this point in the history
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<std::mutex> 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<ThreadGate::threadUp()::{lambda()#1}>(std::unique_lock<std::mutex>&, 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<void, void (*)(HdrHistogram&, ThreadGate&), Hdr2sfMicroSecHistogram&, ThreadGate&>(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<void (*)(HdrHistogram&, ThreadGate&), Hdr2sfMicroSecHistogram&, ThreadGate&>::type std::__invoke<void (*)(HdrHistogram&, ThreadGate&), Hdr2sfMicroSecHistogram&, ThreadGate&>(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<std::tuple<void (*)(HdrHistogram&, ThreadGate&), Hdr2sfMicroSecHistogram&, ThreadGate&> >::_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<std::tuple<void (*)(HdrHistogram&, ThreadGate&), Hdr2sfMicroSecHistogram&, ThreadGate&> >::operator()() /usr/local/include/c++/7.3.0/thread:243
 #9 0x5228687 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(HdrHistogram&, ThreadGate&), Hdr2sfMicroSecHistogram&, ThreadGate&> > >::_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 <[email protected]>
Tested-by: Build Bot <[email protected]>
  • Loading branch information
jimwwalker committed Oct 6, 2020
1 parent 45ff1ec commit b70c733
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion engines/ep/tests/module_tests/hdrhistogram_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ TEST(HdrHistogramTest, ResetItoratorInfLoop) {
}

std::thread thread;
ThreadGate tg(2);
{ // Scope that holds read lock for iterator
auto iter2 = histogram.getHistogramsIterator();
/**
Expand All @@ -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);
Expand Down

0 comments on commit b70c733

Please sign in to comment.