Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect use of the release fence in Singleton::Ref #1208

Closed
Komfr opened this issue May 10, 2023 · 1 comment
Closed

Incorrect use of the release fence in Singleton::Ref #1208

Komfr opened this issue May 10, 2023 · 1 comment

Comments

@Komfr
Copy link

Komfr commented May 10, 2023

Both the last released version 8.7 and the current master branch (2038ab1) have an incorrect order of the release fence and pointer store operations when creating the object.

The current current code is

T *newObject = m_objectFactory();
s_pObject.store(newObject, std::memory_order_relaxed);
std::atomic_thread_fence(std::memory_order_release);

however the correct sequence, which is also described in the article linked from the function documentation, should be

T *newObject = m_objectFactory();
std::atomic_thread_fence(std::memory_order_release);
s_pObject.store(newObject, std::memory_order_relaxed);

Otherwise there is no guarantee that the object content will be already fully stored in the memory when another thread might see the pointer and attempt to access it.

@noloader
Copy link
Collaborator

Thanks @Komfr,

This should be cleared at Commit a23f78d116c9.

We just released Crypto++ 8.8, so this change should get good testing coverage before the next release.

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

No branches or pull requests

2 participants