Skip to content

Conversation

@ITHelpDec
Copy link

@ITHelpDec ITHelpDec commented Jun 4, 2023

Please consider modifying the implicit-boolean ptr check at line 34 to ptr->next.ptr.




Even if the stack is empty while calling the destructor, ptr is a valid pointer from the moment we call head.load() - this leads to undefined behaviour inside one of the atomic fetch operations.


image

image

image

image


Whilst this has been a useful exercise in debugging, please also consider uploading fully-functioning code as a means of verifying that the code published actually functions as intended.

I have attached an example here for anyone coming up against similar issues.

Inside <shared_ptr>

- Current implementation exhibits undefined behaviour

template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _Tp
__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
{
#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
    return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL); <<<<<
//...

- Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ff80feda427)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant