summaryrefslogtreecommitdiffstats
path: root/sys/dev/musycc
diff options
context:
space:
mode:
authorbmilekic <bmilekic@FreeBSD.org>2001-01-06 20:44:39 +0000
committerbmilekic <bmilekic@FreeBSD.org>2001-01-06 20:44:39 +0000
commit00a5e748440a34ada47ccdee2a6a5daf59597586 (patch)
treecc243e45c29d567515181496168399b219d53821 /sys/dev/musycc
parentd20b7bdad1cabae99d52383ab00b455a70558e62 (diff)
downloadFreeBSD-src-00a5e748440a34ada47ccdee2a6a5daf59597586.zip
FreeBSD-src-00a5e748440a34ada47ccdee2a6a5daf59597586.tar.gz
Make sure musycc driver deals with the possibility of any type of mbuf
allocation not succeeding. In this case, make sure the driver doesn't leak any memory by freeing all necessary buffers; make sure to loop and free all the previously allocated mbufs in this routine. Reviewed by: alfred
Diffstat (limited to 'sys/dev/musycc')
-rw-r--r--sys/dev/musycc/musycc.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/sys/dev/musycc/musycc.c b/sys/dev/musycc/musycc.c
index e1817fa..a992bcb 100644
--- a/sys/dev/musycc/musycc.c
+++ b/sys/dev/musycc/musycc.c
@@ -1204,7 +1204,17 @@ musycc_connect(hook_p hook)
sc->mdt[ch][i].data = 0;
MGETHDR(m, M_TRYWAIT, MT_DATA);
+ if (m == NULL)
+ goto errfree;
MCLGET(m, M_TRYWAIT);
+ if ((m->m_flags M_EXT) == 0) {
+ /* We've waited mbuf_wait and still got nothing.
+ We're calling with M_TRYWAIT anyway - a little
+ defensive programming costs us very little - if
+ anything at all in the case of error. */
+ m_free(m);
+ goto errfree;
+ }
sc->mdr[ch][i].m = m;
sc->mdr[ch][i].data = vtophys(m->m_data);
sc->mdr[ch][i].status = 1600; /* MTU */
@@ -1224,6 +1234,16 @@ musycc_connect(hook_p hook)
hook->peer->flags |= HK_QUEUE;
return (0);
+
+errfree:
+ while (i > 0) {
+ /* Don't leak all the previously allocated mbufs in this loop */
+ i--;
+ m_free(sc->mdr[ch][i].m);
+ }
+ FREE(sc->mdt[ch], M_MUSYCC);
+ FREE(sc->mdr[ch], M_MUSYCC);
+ return (ENOBUFS);
}
static int
OpenPOWER on IntegriCloud