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

Free called twice when gpio closed with Isr enabled #1065

Open
ghost opened this issue May 19, 2021 · 5 comments
Open

Free called twice when gpio closed with Isr enabled #1065

ghost opened this issue May 19, 2021 · 5 comments
Labels

Comments

@ghost
Copy link

ghost commented May 19, 2021

In mraa_gpio_close(mraa_gpio_context dev)

    if (dev->events) {
        free(dev->events);
    }
/* Free any ISRs */

mraa_gpio_isr_exit(dev);

In mraa_gpio_isr_exit(mraa_gpio_context dev)

if (dev->events) {
        free(dev->events);
        dev->events = NULL;
    }

Since the dev->events is not assigned null, double free happens. The freeing of events should be defined inside the
mraa_gpio_isr_exit. Two places is not correct

@Propanu
Copy link
Contributor

Propanu commented May 20, 2021

I think you're on to something, the call in mraa_gpio_close(...) should've been removed when c563e4f was merged. Initially the gpio_close and gpio_isr_exit functions were independent and managed by the user, so it did make sense to have both. Is this causing a segfault or any issues for your application?

@ghost
Copy link
Author

ghost commented May 20, 2021

Yes it is showing error for double free. After calling free we are not assigning null. So inside the gpio_isr_exit when it is checked again it assumes it not freed and does the free again.
The second issue is why we need this code in the close. The deleting of the events should be ideally inside the gpio_isr_exit.

@ghost
Copy link
Author

ghost commented May 22, 2021

@Propanu Can I create a branch and provide the fix for the same.

@Propanu
Copy link
Contributor

Propanu commented May 24, 2021

By all means. I will also list this as a bug so it can be included with the next set of patches.

@Propanu Propanu added the bug label May 24, 2021
@GPCExplorer
Copy link

Hi, What's the status resolving this bug?

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

No branches or pull requests

2 participants