Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet Don't leak mbuf if ipfr_fastroute6() fails.



details:   https://anonhg.NetBSD.org/src/rev/9268f7b405d7
branches:  trunk
changeset: 567496:9268f7b405d7
user:      tron <tron%NetBSD.org@localhost>
date:      Wed Jun 16 14:02:39 2004 +0000

description:
Don't leak mbuf if ipfr_fastroute6() fails.

Reviewed by Steve Woodford.

diffstat:

 sys/netinet/ip_fil_netbsd.c |  23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diffs (68 lines):

diff -r 2b788496101c -r 9268f7b405d7 sys/netinet/ip_fil_netbsd.c
--- a/sys/netinet/ip_fil_netbsd.c       Wed Jun 16 12:39:07 2004 +0000
+++ b/sys/netinet/ip_fil_netbsd.c       Wed Jun 16 14:02:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_fil_netbsd.c,v 1.10 2004/05/20 13:55:32 christos Exp $      */
+/*     $NetBSD: ip_fil_netbsd.c,v 1.11 2004/06/16 14:02:39 tron Exp $  */
 
 /*
  * Copyright (C) 1993-2003 by Darren Reed.
@@ -903,8 +903,6 @@
                        return -1;
 
                MCLGET(m, M_DONTWAIT);
-               if (m == NULL)
-                       return -1;
                avail = (m->m_flags & M_EXT) ? MCLBYTES : MHLEN;
                xtra = MIN(fin->fin_plen,
                           avail - hlen - sizeof(*icmp) - max_linkhdr);
@@ -930,7 +928,7 @@
        iclen += xtra;
        m->m_pkthdr.len = iclen;
        if (avail < 0) {
-               m_freem(m);
+               FREE_MB_T(m);
                return -1;
        }
        m->m_len = iclen;
@@ -1031,8 +1029,14 @@
        }
 #endif
 #ifdef USE_INET6
-       if (fin->fin_v == 6)
-               return ipfr_fastroute6(m0, mpp, fin, fdp);
+       if (fin->fin_v == 6) {
+               error = ipfr_fastroute6(m0, mpp, fin, fdp);
+               if ((error != 0) && (*mpp != NULL)) {
+                       FREE_MB_T(*mpp);
+                       *mpp = NULL;
+               }
+               return error;
+       }
 #endif
 
        hlen = fin->fin_hlen;
@@ -1180,6 +1184,7 @@
                MGET(m, M_DONTWAIT, MT_HEADER);
 #endif
                if (m == 0) {
+                       m = m0;
                        error = ENOBUFS;
                        goto bad;
                }
@@ -1325,11 +1330,13 @@
                        dst6 = (struct sockaddr_in6 *)ro->ro_rt->rt_gateway;
                ro->ro_rt->rt_use++;
 
-               if (m0->m_pkthdr.len <= mtu)
+               if (m0->m_pkthdr.len <= mtu) {
+                       *mpp = NULL;
                        error = nd6_output(ifp, fin->fin_ifp, m0,
                                                   dst6, ro->ro_rt);
-               else
+               } else {
                        error = EMSGSIZE;
+               }
        }
 
 bad:



Home | Main Index | Thread Index | Old Index