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

Fix use of not thread safe function localtime() #5211

Merged
merged 2 commits into from
Apr 17, 2022

Conversation

ricrogz
Copy link
Contributor

@ricrogz ricrogz commented Apr 17, 2022

localtime() is not thread safe (https://linux.die.net/man/3/localtime):

The four functions asctime(), ctime(), gmtime() and localtime() return a pointer to static data and hence are not thread-safe.
Thread-safe versions asctime_r(), ctime_r(), gmtime_r() and localtime_r() are specified by SUSv2, and available since libc 5.2.5.

RDkit uses localtime() in logging, and the thread sanitizer flags its usage as a data race. Fortunately, it's easy to fix.

Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably switch this code to use C++ time functions, but that’s clearly a different PR

@greglandrum greglandrum added bug Cleanup Code cleanup and refactoring labels Apr 17, 2022
@greglandrum greglandrum added this to the 2022_03_2 milestone Apr 17, 2022
@greglandrum greglandrum merged commit 5d0be00 into rdkit:master Apr 17, 2022
@ricrogz ricrogz deleted the localtime_not_thread_safe branch April 17, 2022 16:49
greglandrum pushed a commit that referenced this pull request Apr 25, 2022
* fix localtime() not thread safe

* localtime() is thread safe on win32, but not on *nix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Cleanup Code cleanup and refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants