-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Catch and avoid using CHIPMem.h uninitialized #2918
Conversation
#### Problem Some code calls `Platform::Memory…()` allocation functions without having first called `Platform::MemoryInit()`. This is easy to miss because it silently works for the `CHIP_CONFIG_MEMORY_MGMT_MALLOC` configuration. #### Summary of Changes - In debug builds, have `Platform::Memory…()` verify that `Platform::MemoryInit()` has been called. - Fix some existing tests to call `Platform::MemoryInit()`. fixes project-chip#2899
src/lib/support/CHIPMem-Malloc.cpp
Outdated
|
||
#else | ||
|
||
static int memoryInitialized = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be atomic in builds w/ locking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point. And should also check against calling Init while Init'd and Shutdown while shut down.
Possibly a good use for the "nifty counter" (AKA "Schwarz counter") idiom for initializing static objects before first use (as used by iostream to initialize cout)? https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Nifty_Counter |
@kpschoedel can you rebase? should be good to go after that! |
Problem
Some code calls
Platform::Memory…()
allocation functions withouthaving first called
Platform::MemoryInit()
. This is easy to miss becauseit silently works for the
CHIP_CONFIG_MEMORY_MGMT_MALLOC
configuration.Summary of Changes
In debug builds, have
Platform::Memory…()
verify thatPlatform::MemoryInit()
has been called.Fix some existing tests to call
Platform::MemoryInit()
.fixes #2899 CHIPMem.h is sometimes used uninitialized