From a188d6072bda90bc26a1616f3903bab732d7835c Mon Sep 17 00:00:00 2001 From: tron Date: Mon, 1 Mar 2004 13:54:02 +0000 Subject: [PATCH] Don't leak memory if a copyin fails. --- sys/net/if_tun.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index eb714de8ea56..127af914cfad 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_tun.c,v 1.67 2003/09/22 20:49:39 cl Exp $ */ +/* $NetBSD: if_tun.c,v 1.68 2004/03/01 13:54:02 tron Exp $ */ /* * Copyright (c) 1988, Julian Onions @@ -15,7 +15,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.67 2003/09/22 20:49:39 cl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.68 2004/03/01 13:54:02 tron Exp $"); #include "tun.h" @@ -784,16 +784,16 @@ tunwrite(dev, uio, ioflag) } mlen = MHLEN; - top = 0; + top = NULL; mp = ⊤ while (error == 0 && uio->uio_resid > 0) { m->m_len = min(mlen, uio->uio_resid); - error = uiomove(mtod (m, caddr_t), m->m_len, uio); + error = uiomove(mtod(m, caddr_t), m->m_len, uio); *mp = m; mp = &m->m_next; - if (uio->uio_resid > 0) { - MGET (m, M_DONTWAIT, MT_DATA); - if (m == 0) { + if (error == 0 && uio->uio_resid > 0) { + MGET(m, M_DONTWAIT, MT_DATA); + if (m == NULL) { error = ENOBUFS; break; } @@ -801,7 +801,7 @@ tunwrite(dev, uio, ioflag) } } if (error) { - if (top) + if (top != NULL) m_freem (top); ifp->if_ierrors++; simple_unlock(&tp->tun_lock);