Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev Ensure to close open file descriptors.
details: https://anonhg.NetBSD.org/src/rev/ffdbf9c9bc33
branches: trunk
changeset: 825038:ffdbf9c9bc33
user: nat <nat%NetBSD.org@localhost>
date: Tue Jun 27 09:44:13 2017 +0000
description:
Ensure to close open file descriptors.
Patch by pgoyette@.
diffstat:
sys/dev/audiobell.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diffs (49 lines):
diff -r ea3c9372c5ef -r ffdbf9c9bc33 sys/dev/audiobell.c
--- a/sys/dev/audiobell.c Tue Jun 27 09:35:05 2017 +0000
+++ b/sys/dev/audiobell.c Tue Jun 27 09:44:13 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audiobell.c,v 1.23 2017/06/27 09:35:05 nat Exp $ */
+/* $NetBSD: audiobell.c,v 1.24 2017/06/27 09:44:13 nat Exp $ */
/*
@@ -32,7 +32,7 @@
*/
#include <sys/types.h>
-__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.23 2017/06/27 09:35:05 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.24 2017/06/27 09:44:13 nat Exp $");
#include <sys/audioio.h>
#include <sys/conf.h>
@@ -106,10 +106,11 @@
struct uio auio;
struct iovec aiov;
struct file *fp;
- int size, len;
+ int size, len, fd;
KASSERT(volume <= 100);
+ fd = -1;
fp = NULL;
buf = NULL;
audio = AUDIO_DEVICE | device_unit((device_t)v);
@@ -121,6 +122,7 @@
/* If not configured, we can't beep. */
if (audiobellopen(audio, FWRITE, 0, NULL, &fp) != EMOVEFD || fp == NULL)
return;
+ fd = curlwp->l_dupfd; /* save the fd for closing when done */
if (audiobellioctl(fp, AUDIO_GETINFO, &ai) != 0)
goto out;
@@ -174,5 +176,9 @@
out:
if (buf != NULL)
free(buf, M_TEMP);
+ if (fd >= 0) {
+ fd_getfile(fd);
+ fd_close(fd);
+ }
audiobellclose(fp);
}
Home |
Main Index |
Thread Index |
Old Index