-
Notifications
You must be signed in to change notification settings - Fork 52
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
Memory leak when SerialStreamer is used #340
Comments
Most often the panic is in isReadOnlyInline() from incr() when refCount == 1, implying a buffer being copied has been destroyed. I have also seen a panic from decr(). It doesn’t seem to be heap corruption, but that a RefCounted buffer has been released too many times and destroyed. I have seen a panic in CodalHeapAllocator when a ref counted buffer was being freed. I have seen SerialStreamer::lastBuffer crash when assigning a new pull because it’s previous ref counted object has been freed. I think one problem is that the buffer operations are not interrupt safe. I have analysed one example, built with GNU 12.3.1, involving DataStream::nextBuffer, which seems to show DataStream::pull() interrupted at the wrong instant, for a visit to DataStream::pullRequest(), which leads to a double release of DataStream::nextBuffer. A panic occurs as DataStream::pull() tries to return tmp, because its ptr has been released and destroyed. Line numbers above may be different because of added trace code: Without the trace code additions, it can take a lot longer to panic, but it does eventually. See the log below. As I understand it...
Log of RefCounted operations
|
@JohnVidler I didn't have much luck catching it in the debugger, but I added some DMESG to the relevant functions and captured repeated traces like below. SerialStreamer::pullRequest seems indirectly to pull the nextBuffer from the same DataStream (at 0x200024C8) that demux writes to, NRF52ADCChannel::demux calls the ADC channel's non-blocking output DataStream::pullRequest to update its nextBuffer.
Next StreamSplitter::pullRequest routes down through SplitterChannel and StreamNormalizer to SerialStreamer::pullRequest.
SerialStreamer::pullRequest calls pull on StreamNormalizer::output (a blocking DataStream) which routes via StreamNormalizer, SplitterChannel, and StreamSplitter::getBuffer to the ADC channel's output DataStream:pull, which returns the nextBuffer.
|
This programme runs for about 1 min 30 s and then we get a MICROBIT_HEAP_ERROR 030 error.
The text was updated successfully, but these errors were encountered: