sharpdisplay: Fix memory corruption across soft-reset #3497
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It was incorrect to NULL out the pointer to our heap allocated buffer in
reset
, because subsequent to framebuffer_reset, but while the heap was still active, we could callget_bufinfo
again, leading to a fresh allocation on the heap that is about to be destroyed.Typical stack trace:
When this happened -- which was inconsistent -- the display would keep some heap allocation across reset which is exactly what we need to avoid.
NULLing the pointer in reconstruct follows what RGBMatrix does, and that code is a bit more battle-tested anyway.
If I had a motivation for structuring the SharpMemory code differently, I can no longer recall it.
Testing performed: Restarted my complicated calculator program over 100 iterations without observing signs of heap corruption.
Closes: #3473