Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/audio Fix an resource leak on audiobell close.



details:   https://anonhg.NetBSD.org/src/rev/83db8520d904
branches:  trunk
changeset: 466983:83db8520d904
user:      isaki <isaki%NetBSD.org@localhost>
date:      Wed Jan 08 13:30:15 2020 +0000

description:
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().

diffstat:

 sys/dev/audio/audio.c |  24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diffs (80 lines):

diff -r a63ce58b5ce2 -r 83db8520d904 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Wed Jan 08 13:28:14 2020 +0000
+++ b/sys/dev/audio/audio.c     Wed Jan 08 13:30:15 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.38 2020/01/08 13:05:02 isaki Exp $ */
+/*     $NetBSD: audio.c,v 1.39 2020/01/08 13:30:15 isaki Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.38 2020/01/08 13:05:02 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.39 2020/01/08 13:30:15 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -530,6 +530,7 @@
        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 @@
                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 @@
                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;
 }
@@ -2196,6 +2195,8 @@
 
        TRACE(3, "done");
        audio_exit_exclusive(sc);
+
+       kmem_free(file, sizeof(*file));
        return 0;
 }
 
@@ -3055,6 +3056,14 @@
        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.
@@ -7655,6 +7664,7 @@
        mixer_remove(sc);
        mutex_exit(sc->sc_lock);
 
+       kmem_free(file, sizeof(*file));
        return 0;
 }
 



Home | Main Index | Thread Index | Old Index