Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb Don't leak memory in case of a realloc failure.
details: https://anonhg.NetBSD.org/src/rev/8afd3ae0da57
branches: trunk
changeset: 509772:8afd3ae0da57
user: christos <christos%NetBSD.org@localhost>
date: Sat May 12 19:18:57 2001 +0000
description:
Don't leak memory in case of a realloc failure.
Reported by: grendel%heorot.stanford.edu@localhost (Ted U)
diffstat:
sys/dev/usb/uaudio.c | 30 +++++++++++++++---------------
1 files changed, 15 insertions(+), 15 deletions(-)
diffs (58 lines):
diff -r 2db95f1a9f13 -r 8afd3ae0da57 sys/dev/usb/uaudio.c
--- a/sys/dev/usb/uaudio.c Sat May 12 18:07:20 2001 +0000
+++ b/sys/dev/usb/uaudio.c Sat May 12 19:18:57 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uaudio.c,v 1.41 2001/01/23 14:04:13 augustss Exp $ */
+/* $NetBSD: uaudio.c,v 1.42 2001/05/12 19:18:57 christos Exp $ */
/*
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -541,17 +541,16 @@
uaudio_mixer_add_ctl(struct uaudio_softc *sc, struct mixerctl *mc)
{
int res;
+ size_t len = sizeof(*mc) * (sc->sc_nctls + 1);
+ struct mixerctl *nmc = sc->sc_nctls == 0 ?
+ malloc(len, M_USBDEV, M_NOWAIT) :
+ realloc(sc->sc_ctls, len, M_USBDEV, M_NOWAIT);
- if (sc->sc_nctls == 0)
- sc->sc_ctls = malloc(sizeof *mc, M_USBDEV, M_NOWAIT);
- else
- sc->sc_ctls = realloc(sc->sc_ctls,
- (sc->sc_nctls+1) * sizeof *mc,
- M_USBDEV, M_NOWAIT);
- if (sc->sc_ctls == NULL) {
+ if (nmc == NULL) {
printf("uaudio_mixer_add_ctl: no memory\n");
return;
}
+ sc->sc_ctls = nmc;
mc->delta = 0;
if (mc->type != MIX_ON_OFF) {
@@ -1022,16 +1021,17 @@
void
uaudio_add_alt(struct uaudio_softc *sc, struct as_info *ai)
{
- if (sc->sc_nalts == 0)
- sc->sc_alts = malloc(sizeof *ai, M_USBDEV, M_NOWAIT);
- else
- sc->sc_alts = realloc(sc->sc_alts,
- (sc->sc_nalts+1) * sizeof *ai,
- M_USBDEV, M_NOWAIT);
- if (sc->sc_alts == NULL) {
+ size_t len = sizeof(*ai) * (sc->sc_nalts + 1);
+ struct as_info *nai = sc->sc_nalts == 0 ?
+ malloc(len, M_USBDEV, M_NOWAIT) :
+ realloc(sc->sc_alts, len, M_USBDEV, M_NOWAIT);
+
+ if (nai == NULL) {
printf("uaudio_add_alt: no memory\n");
return;
}
+
+ sc->sc_alts = nai;
DPRINTFN(2,("uaudio_add_alt: adding alt=%d, enc=%d\n",
ai->alt, ai->encoding));
sc->sc_alts[sc->sc_nalts++] = *ai;
Home |
Main Index |
Thread Index |
Old Index