-
Notifications
You must be signed in to change notification settings - Fork 61
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
protect Config #13
protect Config #13
Conversation
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.
Nice catch. Just need Doc to review this too!
If it is inside the method, my understanding is that the memory is allocated on the stack and on leaving the method the memory is freed. |
Mmmhhhmmm, |
You probably are completely correct. Maybe this was also not such a big deal in the past because I remember that I used to use String as parameter and later changed it for const char * wherever possible to save memory too... but it could lead to garbled names which in fact i have seen. |
Is there a need at all to copy the config buffer into another buffer? Hmm... thinking out loud here... while I am checking the code... Yes, there is: from the strtok_r documentation So we have to duplicate the string... ok. This is also true for the strtok version (non re-entrant) |
@danecreekphotography, a copy of the config Buffet is not really required, I have a branch where I already tested it. But there is still some work required (after writing a config the Connector gives an error) I know what to do but is a little bit difficult during my vacation ;) |
Firmware for this pull request: |
Firmware for this pull request: |
Small change but a longer explanation:
Within readConfig() readBuffer[MEM_LEN_CONFIG + 1] is defined and a RAM area is reserved. Then the config (String cfg) is copied to readBuffer[].
In the nexr steps readBuffer[] is processed, all "." and ":" are exchanged to NULL (string termination) and for each device pointers are defined which are pointing to this reserved RAM area.
At the end of the function readBuffer[] this RAM area is released, but the pointer are sstill pointing to this RAM area.
In the following program it can happen, that additional RAM is required and that the remaining RAM area is not sufficient. In this case the released RAM area from readConfig[] is used and the config is mixed up.
Defining readBuffer[MEM_LEN_CONFIG + 1] globally will avoid that this RAM area will be used again.
I have an other idea not to double the config but still to use the original buffer. This would save additional 256 Bytes of RAM. Most is working but I need some more time to finish this. But for now I would stay with this change.
/edit: 256 Bytes for the ProMicro which is already short of memory
Fixes #14