https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122683

            Bug ID: 122683
           Summary: In unique_lock.h unlock()  routine, _M_owns is
                    accessed without lock
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: moti.haimovski at intel dot com
  Target Milestone: ---

Found by Coverity tests run by me on v11
(/usr/include/c++/11/bits/unique_lock.h)
Also found by RedHat running Coverity tests
(https://people.redhat.com/bhubbard/cov-html-int-2019-10-09/1/152unique_lock.h.html)
Issue is seen also on latest releases.

Detailed test results are below:

     void
189      unlock()
190      {

1. Condition !this->_M_owns, taking false branch.
191        if (!_M_owns)
192          __throw_system_error(int(errc::operation_not_permitted));

2. Condition this->_M_device, taking true branch.
193        else if (_M_device)
194          {
195            _M_device->unlock();

CID 10065 (#3 of 3): Data race condition (MISSING_LOCK)3. missing_lock:
Accessing this->_M_owns without holding lock
std::unique_lock<std::mutex>._M_device. Elsewhere,
_ZSt11unique_lockISt5mutexE._M_owns is accessed with
std::unique_lock<std::mutex>._M_device held 1 out of 2 times (1 of these
accesses strongly imply that it is necessary).
196            _M_owns = false;
197          }
198      }
199

Reply via email to