Skip to content

gpiod: repeatable segfault when releasing second set of claimed lines on a single chip #1

@Gadgetoid

Description

@Gadgetoid

Afaict this code always results in a segfault when b.release() is called. Presumably somewhere in the plumbing of gpiod there's an assumption that there will only be one claim against a given gpiochip device, this cannot be guaranteed across multi-library Python projects.

Notably, simply omitting any cleanup - I had .release() in an atexit handler in the Blinkt! lib - fixes this, so perhaps we can just rely on the lines being implicitly released. Though again this may not be possible to guarantee in some cases.

Repro (given line and chip values are GPIO23 and GPIO24 on a Raspberry Pi 400, a Pi 5 would use /dev/gpiochip4):

import gpiod
from gpiod.line import Direction, Value

a = gpiod.request_lines("/dev/gpiochip0", consumer="test", config={
    23: gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE)
})

b = gpiod.request_lines("/dev/gpiochip0", consumer="test", config={
    24: gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE)
})

a.release()
b.release()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions