From b7ebb8e1c90739611999f66e720a291d2988e6cb Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 2 Jan 2017 14:55:25 +0100 Subject: [PATCH] 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 --- core.c | 7 +++++++ 1 file changed, 7 insertions(+) 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); -- 2.30.2