Module Name: src
Committed By: martin
Date: Tue Jan 21 11:19:19 UTC 2020
Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c
Log Message:
Pull up following revision(s) (requested by isaki in ticket #620):
sys/dev/audio/audio.c: revision 1.39
Fix an resource leak on audiobell close.
audioclose() freed audio_file_t structure, but only audiobellclose
didn't pass there. I change that all of freeing audio_file_t is done
by each *_close().
To generate a diff of this commit:
cvs rdiff -u -r1.28.2.6 -r1.28.2.7 src/sys/dev/audio/audio.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.6 src/sys/dev/audio/audio.c:1.28.2.7
--- src/sys/dev/audio/audio.c:1.28.2.6 Tue Jan 21 11:17:58 2020
+++ src/sys/dev/audio/audio.c Tue Jan 21 11:19:19 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: audio.c,v 1.28.2.6 2020/01/21 11:17:58 martin Exp $ */
+/* $NetBSD: audio.c,v 1.28.2.7 2020/01/21 11:19:19 martin Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.6 2020/01/21 11:17:58 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.7 2020/01/21 11:19:19 martin Exp $");
#ifdef _KERNEL_OPT
#include "audio.h"
@@ -530,6 +530,7 @@ static int audio_mmap(struct audio_softc
struct uvm_object **, int *, audio_file_t *);
static int audioctl_open(dev_t, struct audio_softc *, int, int, struct lwp *);
+static int audioctl_close(struct audio_softc *, audio_file_t *);
static void audio_pintr(void *);
static void audio_rintr(void *);
@@ -1521,7 +1522,7 @@ audioclose(struct file *fp)
error = audio_close(sc, file);
break;
case AUDIOCTL_DEVICE:
- error = 0;
+ error = audioctl_close(sc, file);
break;
case MIXER_DEVICE:
error = mixer_close(sc, file);
@@ -1530,10 +1531,8 @@ audioclose(struct file *fp)
error = ENXIO;
break;
}
- if (error == 0) {
- kmem_free(fp->f_audioctx, sizeof(audio_file_t));
- fp->f_audioctx = NULL;
- }
+ /* f_audioctx has already been freed in lower *_close() */
+ fp->f_audioctx = NULL;
return error;
}
@@ -2201,6 +2200,8 @@ audio_close(struct audio_softc *sc, audi
TRACE(3, "done");
audio_exit_exclusive(sc);
+
+ kmem_free(file, sizeof(*file));
return 0;
}
@@ -3060,6 +3061,14 @@ audioctl_open(dev_t dev, struct audio_so
return error;
}
+static int
+audioctl_close(struct audio_softc *sc, audio_file_t *file)
+{
+
+ kmem_free(file, sizeof(*file));
+ return 0;
+}
+
/*
* Free 'mem' if available, and initialize the pointer.
* For this reason, this is implemented as macro.
@@ -7660,6 +7669,7 @@ mixer_close(struct audio_softc *sc, audi
mixer_remove(sc);
mutex_exit(sc->sc_lock);
+ kmem_free(file, sizeof(*file));
return 0;
}