From owner-cvs-all Sat Jan 6 13:29:48 2001 From owner-cvs-all@FreeBSD.ORG Sat Jan 6 13:29:43 2001 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id 9A83537B400; Sat, 6 Jan 2001 13:29:43 -0800 (PST) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id f06LThK21111; Sat, 6 Jan 2001 13:29:43 -0800 (PST) Date: Sat, 6 Jan 2001 13:29:43 -0800 From: Alfred Perlstein To: Bosko Milekic Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sys/dev/musycc musycc.c Message-ID: <20010106132943.E15744@fw.wintelcom.net> References: <200101062044.f06Kiex42615@freefall.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200101062044.f06Kiex42615@freefall.freebsd.org>; from bmilekic@FreeBSD.org on Sat, Jan 06, 2001 at 12:44:40PM -0800 Sender: bright@fw.wintelcom.net Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * Bosko Milekic [010106 12:44] wrote: > bmilekic 2001/01/06 12:44:40 PST > > Modified files: > sys/dev/musycc musycc.c > Log: > 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 Grr, This isn't how it was supposed to be done. Would you mind terribly if I cleaned it up to what I intended it to be: Index: musycc.c =================================================================== RCS file: /home/ncvs/src/sys/dev/musycc/musycc.c,v retrieving revision 1.14 diff -u -c -r1.14 musycc.c cvs server: conflicting specifications of output style *** musycc.c 2001/01/06 20:44:39 1.14 --- musycc.c 2001/01/06 21:28:57 *************** *** 1207,1220 **** 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 */ --- 1207,1214 ---- if (m == NULL) goto errfree; MCLGET(m, M_TRYWAIT); ! if ((m->m_flags M_EXT) == 0) goto errfree; sc->mdr[ch][i].m = m; sc->mdr[ch][i].data = vtophys(m->m_data); sc->mdr[ch][i].status = 1600; /* MTU */ *************** *** 1236,1241 **** --- 1230,1237 ---- return (0); errfree: + if (m != NULL) + m_free(m); while (i > 0) { /* Don't leak all the previously allocated mbufs in this loop */ i--; -- -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] "I have the heart of a child; I keep it in a jar on my desk." To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message