iio: Check fd against != -1 and not > 0 and avoid leaks during error handling
[contrib/mraa.git] / src / mraa.c
index 073e1ba..355924d 100644 (file)
@@ -220,7 +220,7 @@ mraa_iio_detect()
         device->num = i;
         snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d/name", i);
         fd = open(filepath, O_RDONLY);
-        if (fd > 0) {
+        if (fd != -1) {
             len = read(fd, &name, 64);
             if (len > 1) {
                 // remove any trailing CR/LF symbols