Fix fd leak in error case. Found by cppcheck.

This commit is contained in:
wiz 2011-01-04 09:25:21 +00:00
parent 7e975aaf96
commit 7892952169
3 changed files with 36 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ofhandlers.c,v 1.4 2008/04/28 20:24:15 martin Exp $ */
/* $NetBSD: ofhandlers.c,v 1.5 2011/01/04 09:25:21 wiz Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -106,8 +106,10 @@ of_handler(keyword, arg)
if (strcmp(ex->ex_keyword, keyword) == 0)
break;
if (ioctl(fd, OFIOCGETOPTNODE, (char *)&optnode) < 0)
if (ioctl(fd, OFIOCGETOPTNODE, (char *)&optnode) < 0) {
(void)close(fd);
BARF("OFIOCGETOPTNODE", strerror(errno));
}
memset(&ofio_buf[0], 0, sizeof(ofio_buf));
memset(&ofio, 0, sizeof(ofio));
@ -121,8 +123,10 @@ of_handler(keyword, arg)
ofio.of_buf = &ofio_buf[0];
ofio.of_buflen = sizeof(ofio_buf);
if (ioctl(fd, OFIOCGET, (char *)&ofio) < 0)
if (ioctl(fd, OFIOCGET, (char *)&ofio) < 0) {
(void)close(fd);
BARF("OFIOCGET", strerror(errno));
}
if (ofio.of_buflen <= 0) {
printf("nothing available for %s\n", keyword);
@ -142,8 +146,10 @@ of_handler(keyword, arg)
ofio.of_buflen = strlen(arg);
}
if (ioctl(fd, OFIOCSET, (char *)&ofio) < 0)
if (ioctl(fd, OFIOCSET, (char *)&ofio) < 0) {
(void)close(fd);
BARF("invalid keyword", keyword);
}
if (verbose) {
printf("new: ");
@ -155,8 +161,10 @@ of_handler(keyword, arg)
} else {
ofio.of_buf = &ofio_buf[0];
ofio.of_buflen = sizeof(ofio_buf);
if (ioctl(fd, OFIOCGET, (char *)&ofio) < 0)
if (ioctl(fd, OFIOCGET, (char *)&ofio) < 0) {
(void)close(fd);
BARF("OFIOCGET", strerror(errno));
}
if (ofio.of_buflen <= 0) {
(void)snprintf(err_str, sizeof err_str,

View File

@ -1,4 +1,4 @@
/* $NetBSD: ophandlers.c,v 1.10 2008/04/28 20:24:15 martin Exp $ */
/* $NetBSD: ophandlers.c,v 1.11 2011/01/04 09:25:21 wiz Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -114,8 +114,10 @@ op_handler(keyword, arg)
if (strcmp(ex->ex_keyword, keyword) == 0)
break;
if (ioctl(fd, OPIOCGETOPTNODE, (char *)&optnode) < 0)
if (ioctl(fd, OPIOCGETOPTNODE, (char *)&optnode) < 0) {
(void)close(fd);
BARF("OPIOCGETOPTNODE", strerror(errno));
}
memset(&opio_buf[0], 0, sizeof(opio_buf));
memset(&opio, 0, sizeof(opio));
@ -129,8 +131,10 @@ op_handler(keyword, arg)
opio.op_buf = &opio_buf[0];
opio.op_buflen = sizeof(opio_buf);
if (ioctl(fd, OPIOCGET, (char *)&opio) < 0)
if (ioctl(fd, OPIOCGET, (char *)&opio) < 0) {
(void)close(fd);
BARF("OPIOCGET", strerror(errno));
}
if (opio.op_buflen <= 0) {
printf("nothing available for %s\n", keyword);
@ -150,8 +154,10 @@ op_handler(keyword, arg)
opio.op_buflen = strlen(arg);
}
if (ioctl(fd, OPIOCSET, (char *)&opio) < 0)
if (ioctl(fd, OPIOCSET, (char *)&opio) < 0) {
(void)close(fd);
BARF("invalid keyword", keyword);
}
if (verbose) {
printf("new: ");
@ -163,8 +169,10 @@ op_handler(keyword, arg)
} else {
opio.op_buf = &opio_buf[0];
opio.op_buflen = sizeof(opio_buf);
if (ioctl(fd, OPIOCGET, (char *)&opio) < 0)
if (ioctl(fd, OPIOCGET, (char *)&opio) < 0) {
(void)close(fd);
BARF("OPIOCGET", strerror(errno));
}
if (opio.op_buflen <= 0) {
(void)snprintf(err_str, sizeof err_str,

View File

@ -1,4 +1,4 @@
/* $NetBSD: prephandlers.c,v 1.2 2008/04/28 20:24:15 martin Exp $ */
/* $NetBSD: prephandlers.c,v 1.3 2011/01/04 09:25:21 wiz Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -111,8 +111,10 @@ prep_handler(char *keyword, char *arg)
nvio.pnv_buf = &nvio_buf[0];
nvio.pnv_buflen = sizeof(nvio_buf);
if (ioctl(fd, PNVIOCGET, (char *) &nvio) < 0)
if (ioctl(fd, PNVIOCGET, (char *) &nvio) < 0) {
(void)close(fd);
BARF("PNVIOCGET", strerror(errno));
}
if (nvio.pnv_buflen <= 0) {
printf("nothing available for %s\n", keyword);
@ -131,8 +133,10 @@ out:
nvio.pnv_buflen = strlen(arg);
}
if (ioctl(fd, PNVIOCSET, (char *) &nvio) < 0)
if (ioctl(fd, PNVIOCSET, (char *) &nvio) < 0) {
(void)close(fd);
BARF("invalid keyword", keyword);
}
if (verbose) {
printf("new: ");
@ -144,8 +148,10 @@ out:
} else {
nvio.pnv_buf = &nvio_buf[0];
nvio.pnv_buflen = sizeof(nvio_buf);
if (ioctl(fd, PNVIOCGET, (char *) &nvio) < 0)
if (ioctl(fd, PNVIOCGET, (char *) &nvio) < 0) {
(void)close(fd);
BARF("PNVIOCGET", strerror(errno));
}
if (nvio.pnv_buflen <= 0) {
(void) snprintf(err_str, sizeof err_str,