From: Ruben Kerkhof Date: Fri, 4 Dec 2015 20:56:40 +0000 (+0100) Subject: multimeter plugin: fix fd leak X-Git-Tag: collectd-5.5.1~31^2~3 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b8913bc047474aa0a3bfbf03ecbb3b5050605ed1;p=collectd.git multimeter plugin: fix fd leak If open returns 0 we leak fd. CID #38016 Signed-off-by: Florian Forster --- diff --git a/src/multimeter.c b/src/multimeter.c index 775eb57e..03608e6c 100644 --- a/src/multimeter.c +++ b/src/multimeter.c @@ -153,9 +153,9 @@ static int multimeter_init (void) for (i = 0; i < 10; i++) { - device[strlen(device)-1] = i + '0'; + device[strlen(device)-1] = i + '0'; - if ((fd = open(device, O_RDWR | O_NOCTTY)) > 0) + if ((fd = open(device, O_RDWR | O_NOCTTY)) != -1) { struct termios tios; int rts = TIOCM_RTS; @@ -171,7 +171,7 @@ static int multimeter_init (void) tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &tios); ioctl(fd, TIOCMBIC, &rts); - + if (multimeter_read_value (&value) < -1) { close (fd);