From: Adrian Szyndela Date: Fri, 20 Aug 2021 08:34:29 +0000 (+0200) Subject: gpio: eliminate file descriptor leak X-Git-Tag: submit/tizen/20210820.100048~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F30%2F262830%2F1;p=platform%2Fcore%2Fapi%2Fperipheral-io.git gpio: eliminate file descriptor leak Once in the loop, fd_chip can be left unclosed if configuration file does not match the system and next iteration is required. This commit makes fd_chip closed just at the end of the current iteration, before entering another iteration. Change-Id: I8d7102ba01d0ca30d63e5b634199792368a98297 --- diff --git a/src/peripheral_gpio_modern_api.c b/src/peripheral_gpio_modern_api.c index 21e68f9..d3d07cb 100644 --- a/src/peripheral_gpio_modern_api.c +++ b/src/peripheral_gpio_modern_api.c @@ -207,16 +207,16 @@ int gpio_modern_open(struct gpio_modern_data *mdata, int gpio_pin, GHashTable *c gpointer base_as_ptr; bool found = g_hash_table_lookup_extended(chip_to_base, chip_info.label, NULL, &base_as_ptr); - if (!found) - continue; - int base = GPOINTER_TO_INT(base_as_ptr); - - if (gpio_pin >= base && gpio_pin < base + chip_info.lines) { - line = gpio_pin - base; - break; - } else { - cleanup_fd(&fd_chip); + if (found) { + int base = GPOINTER_TO_INT(base_as_ptr); + + if (gpio_pin >= base && gpio_pin < base + chip_info.lines) { + line = gpio_pin - base; + break; + } } + + cleanup_fd(&fd_chip); } struct gpioline_info line_info;