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

Equeue unchain bugs #8567

Closed
marcemmers opened this issue Oct 29, 2018 · 2 comments
Closed

Equeue unchain bugs #8567

marcemmers opened this issue Oct 29, 2018 · 2 comments

Comments

@marcemmers
Copy link
Contributor

marcemmers commented Oct 29, 2018

Description

We have run into some issues when we need to unchain and chain a queue multiple times. After a certain amount of those sequences we encountered a hardfault.

We are running mbed os 5.10.0 at the moment but there haven't been any changes to this since.

There are 2 separate issues which caused the hardfault.
The first is the actual memory leak which seems to happen in this example:

EventQueue q1;
EventQueue q2;

void main() {
while( true ) {
q1.chain( &q2 ); // Chain q2 to q1
q1.chain( NULL ); // Remove chain from q1
//This second step should free the memory from the chained q2 event.
}
}

What actually happens is that on the first chain, there is memory allocated from the slab of q1 to place the chained q2 event. This seems to be the wanted behaviour. Unchaining removes the event from the q1 queue but places the chunk that was allocated from the q1 slab in the chunk list of q2. The chuck can never be used by q1 again which means it is sort of a memory leak looking from the q1 perspective.

To me it looks like line 604 in equeue.c calls dealloc on the wrong object. This line should be:
equeue_dealloc(c->q, c); instead of equeue_dealloc(c->target, c);

The second issue is the fact that the chain function does not check if equeue_alloc returns a valid pointer or a null. This resulted in the hardfault further on because of using null where that was not possible. This could be easily fixed by checking the pointer and returning an error code.

Issue request type

[ ] Question
[ ] Enhancement
[x] Bug

@ciarmcom
Copy link
Member

Internal Jira reference: https://jira.arm.com/browse/MBOCUSTRIA-114

@cmonr
Copy link
Contributor

cmonr commented Jan 3, 2019

Fix was brought in: #9066

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants