From: Bartosz Golaszewski Date: Mon, 2 Jan 2017 13:55:25 +0000 (+0100) Subject: core: release all lines in gpiod_chip_close() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=b7ebb8e1c90739611999f66e720a291d2988e6cb;p=qemu-gpiodev%2Flibgpiod.git core: release all lines in gpiod_chip_close() This fixes a memory leak if the user forgets to explicitly release requested lines. Signed-off-by: Bartosz Golaszewski --- diff --git a/core.c b/core.c index 077c116..cc72c4d 100644 --- a/core.c +++ b/core.c @@ -382,6 +382,13 @@ struct gpiod_chip * gpiod_chip_open_lookup(const char *descr) void gpiod_chip_close(struct gpiod_chip *chip) { + unsigned int i; + + for (i = 0; i < chip->cinfo.lines; i++) { + if (chip->lines[i].requested) + gpiod_line_release(&chip->lines[i]); + } + close(chip->fd); free(chip->lines); free(chip);