From 58cf292dfc90340b15052ac86de641b6516badbe Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Mon, 21 Dec 2015 15:38:20 +0000 Subject: [PATCH] iio.c: Closedir correctly and return error if we fail to read from the device dir Signed-off-by: Brendan Le Foll --- src/iio/iio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/iio/iio.c b/src/iio/iio.c index 1aee9fe..f15a337 100644 --- a/src/iio/iio.c +++ b/src/iio/iio.c @@ -599,6 +599,8 @@ mraa_iio_update_channels(mraa_iio_context dev) if (read(fd, readbuf, 2 * sizeof(char)) != 2) { syslog(LOG_ERR, "iio: Failed to read a sensible value from sysfs"); free(str); + close(fd); + closedir(dir); return -1; } chan->enabled = (int) strtol(readbuf, NULL, 10); @@ -617,8 +619,11 @@ mraa_iio_update_channels(mraa_iio_context dev) } } } + closedir(dir); + return MRAA_SUCCESS; } - return MRAA_SUCCESS; + + return MRAA_ERROR_INVALID_HANDLE; } mraa_result_t -- 2.7.4