From d222ec102452790a07d27adfb297117b83d135bb Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 14 Oct 2017 00:17:45 -0400 Subject: linux: Make sure to close fd on analog/pca9685 init failure Signed-off-by: Kevin O'Connor --- src/linux/analog.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/linux/analog.c') diff --git a/src/linux/analog.c b/src/linux/analog.c index c909e286..990f6c4a 100644 --- a/src/linux/analog.c +++ b/src/linux/analog.c @@ -26,14 +26,16 @@ gpio_adc_setup(uint8_t pin) int fd = open(fname, O_RDONLY|O_CLOEXEC); if (fd < 0) { report_errno("analog open", fd); - shutdown("Unable to open adc path"); + goto fail; } int ret = set_non_blocking(fd); - if (ret < 0) { - report_errno("analog set_non_blocking", ret); - shutdown("Unable to set non blocking on adc path"); - } + if (ret < 0) + goto fail; return (struct gpio_adc){ .fd = fd }; +fail: + if (fd >= 0) + close(fd); + shutdown("Unable to open adc device"); } uint32_t -- cgit v1.2.3-70-g09d2