Fix fd leaks. Found by cppcheck.

This commit is contained in:
wiz 2011-01-04 23:48:44 +00:00
parent 80172dbf65
commit a88611257c

View File

@ -1,4 +1,4 @@
/* $NetBSD: wdogctl.c,v 1.18 2009/03/16 13:37:45 lukem Exp $ */ /* $NetBSD: wdogctl.c,v 1.19 2011/01/04 23:48:44 wiz Exp $ */
/*- /*-
* Copyright (c) 2000 Zembu Labs, Inc. * Copyright (c) 2000 Zembu Labs, Inc.
@ -35,7 +35,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: wdogctl.c,v 1.18 2009/03/16 13:37:45 lukem Exp $"); __RCSID("$NetBSD: wdogctl.c,v 1.19 2011/01/04 23:48:44 wiz Exp $");
#endif #endif
@ -200,6 +200,8 @@ enable_kernel(const char *name, u_int period)
if (ioctl(fd, WDOGIOC_SMODE, &wm) == -1) if (ioctl(fd, WDOGIOC_SMODE, &wm) == -1)
err(EXIT_FAILURE, "WDOGIOC_SMODE"); err(EXIT_FAILURE, "WDOGIOC_SMODE");
(void)close(fd);
} }
void void
@ -219,6 +221,8 @@ enable_ext(const char *name, u_int period)
if (ioctl(fd, WDOGIOC_TICKLE) == -1) if (ioctl(fd, WDOGIOC_TICKLE) == -1)
syslog(LOG_EMERG, "unable to tickle watchdog timer %s: %m", syslog(LOG_EMERG, "unable to tickle watchdog timer %s: %m",
wm.wm_name); wm.wm_name);
(void)close(fd);
return; return;
} }
@ -316,6 +320,8 @@ tickle_ext()
err(EXIT_FAILURE, "open %s", _PATH_WATCHDOG); err(EXIT_FAILURE, "open %s", _PATH_WATCHDOG);
if (ioctl(fd, WDOGIOC_TICKLE) == -1) if (ioctl(fd, WDOGIOC_TICKLE) == -1)
fprintf(stderr, "Cannot tickle timer\n"); fprintf(stderr, "Cannot tickle timer\n");
(void)close(fd);
} }
void void
@ -331,6 +337,7 @@ disable(void)
if (ioctl(fd, WDOGIOC_WHICH, &wm) == -1) { if (ioctl(fd, WDOGIOC_WHICH, &wm) == -1) {
printf("No watchdog timer running.\n"); printf("No watchdog timer running.\n");
(void)close(fd);
return; return;
} }
mode = wm.wm_mode & WDOG_MODE_MASK; mode = wm.wm_mode & WDOG_MODE_MASK;