Source-Changes-HG archive

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

[src/trunk]: src/sys/nfs plug mbuf leak due to manual mbuf handling. PR kern...



details:   https://anonhg.NetBSD.org/src/rev/35aab5748e0f
branches:  trunk
changeset: 552749:35aab5748e0f
user:      itojun <itojun%NetBSD.org@localhost>
date:      Thu Oct 02 06:01:51 2003 +0000

description:
plug mbuf leak due to manual mbuf handling.  PR kern/13807.
(martti confirmed that it stabilizes the situation described in kren/13807)

diffstat:

 sys/nfs/nfs_subs.c   |  22 +++++++++++++++-------
 sys/nfs/nfs_vfsops.c |  11 +++++++----
 2 files changed, 22 insertions(+), 11 deletions(-)

diffs (91 lines):

diff -r 37e8b79afeb7 -r 35aab5748e0f sys/nfs/nfs_subs.c
--- a/sys/nfs/nfs_subs.c        Thu Oct 02 02:26:17 2003 +0000
+++ b/sys/nfs/nfs_subs.c        Thu Oct 02 06:01:51 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs_subs.c,v 1.128 2003/09/26 11:51:53 yamt Exp $      */
+/*     $NetBSD: nfs_subs.c,v 1.129 2003/10/02 06:01:51 itojun Exp $    */
 
 /*
  * Copyright (c) 1989, 1993
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.128 2003/09/26 11:51:53 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.129 2003/10/02 06:01:51 itojun Exp $");
 
 #include "fs_nfs.h"
 #include "opt_nfs.h"
@@ -1029,27 +1029,35 @@
                        m1->m_next = m2;
                }
                m1->m_len = 0;
-               dst = m1->m_dat;
+               if (m1->m_flags & M_PKTHDR)
+                       dst = m1->m_pktdat;
+               else
+                       dst = m1->m_dat;
+               m1->m_data = dst;
        } else {
                /*
                 * If the first mbuf has no external data
                 * move the data to the front of the mbuf.
                 */
-               if ((dst = m1->m_dat) != src)
+               if (m1->m_flags & M_PKTHDR)
+                       dst = m1->m_pktdat;
+               else
+                       dst = m1->m_dat;
+               m1->m_data = dst;
+               if (dst != src)
                        memmove(dst, src, left);
                dst += left; 
                m1->m_len = left;
                m2 = m1->m_next;
        }
-       m1->m_flags &= ~M_PKTHDR;
-       *cp2 = m1->m_data = m1->m_dat;   /* data is at beginning of buffer */
+       *cp2 = m1->m_data;
        *dposp = mtod(m1, caddr_t) + siz;
        /*
         * Loop through mbufs pulling data up into first mbuf until
         * the first mbuf is full or there is no more data to
         * pullup.
         */
-       while ((len = (MLEN - m1->m_len)) != 0 && m2) {
+       while ((len = M_TRAILINGSPACE(m1)) != 0 && m2) {
                if ((len = min(len, m2->m_len)) != 0)
                        memcpy(dst, m2->m_data, len);
                m1->m_len += len;
diff -r 37e8b79afeb7 -r 35aab5748e0f sys/nfs/nfs_vfsops.c
--- a/sys/nfs/nfs_vfsops.c      Thu Oct 02 02:26:17 2003 +0000
+++ b/sys/nfs/nfs_vfsops.c      Thu Oct 02 06:01:51 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs_vfsops.c,v 1.132 2003/08/07 16:33:54 agc Exp $     */
+/*     $NetBSD: nfs_vfsops.c,v 1.133 2003/10/02 06:01:51 itojun Exp $  */
 
 /*
  * Copyright (c) 1989, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.132 2003/08/07 16:33:54 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.133 2003/10/02 06:01:51 itojun Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -168,8 +168,11 @@
        if (v3)
                nfsm_postop_attr(vp, retattr, 0);
        if (error) {
-               if (mrep != NULL)
-                       m_free(mrep);
+               if (mrep != NULL) {
+                       if (mrep->m_next != NULL)
+                               printf("nfs_vfsops: nfs_statfs would loose buffers\n");
+                       m_freem(mrep);
+               }
                goto nfsmout;
        }
        nfsm_dissect(sfp, struct nfs_statfs *, NFSX_STATFS(v3));



Home | Main Index | Thread Index | Old Index