Author: mjg
Date: Sun Aug 24 12:51:12 2014
New Revision: 270456
URL: http://svnweb.freebsd.org/changeset/base/270456

Log:
  Plug a memory leak in case of failed lookups in capability mode.
  
  Put common cnp cleanup into one function and use it for this purpose.
  
  MFC after:    1 week

Modified:
  head/sys/kern/vfs_lookup.c

Modified: head/sys/kern/vfs_lookup.c
==============================================================================
--- head/sys/kern/vfs_lookup.c  Sun Aug 24 12:50:50 2014        (r270455)
+++ head/sys/kern/vfs_lookup.c  Sun Aug 24 12:51:12 2014        (r270456)
@@ -119,6 +119,16 @@ SYSCTL_INT(_vfs, OID_AUTO, lookup_shared
  *             if symbolic link, massage name in buffer and continue
  *     }
  */
+static void
+namei_cleanup_cnp(struct componentname *cnp)
+{
+       uma_zfree(namei_zone, cnp->cn_pnbuf);
+#ifdef DIAGNOSTIC
+       cnp->cn_pnbuf = NULL;
+       cnp->cn_nameptr = NULL;
+#endif
+}
+
 int
 namei(struct nameidata *ndp)
 {
@@ -183,11 +193,7 @@ namei(struct nameidata *ndp)
        }
 #endif
        if (error) {
-               uma_zfree(namei_zone, cnp->cn_pnbuf);
-#ifdef DIAGNOSTIC
-               cnp->cn_pnbuf = NULL;
-               cnp->cn_nameptr = NULL;
-#endif
+               namei_cleanup_cnp(cnp);
                ndp->ni_vp = NULL;
                return (error);
        }
@@ -254,11 +260,7 @@ namei(struct nameidata *ndp)
                        }
                }
                if (error) {
-                       uma_zfree(namei_zone, cnp->cn_pnbuf);
-#ifdef DIAGNOSTIC
-                       cnp->cn_pnbuf = NULL;
-                       cnp->cn_nameptr = NULL;
-#endif
+                       namei_cleanup_cnp(cnp);
                        return (error);
                }
        }
@@ -284,6 +286,7 @@ namei(struct nameidata *ndp)
                                if (KTRPOINT(curthread, KTR_CAPFAIL))
                                        ktrcapfail(CAPFAIL_LOOKUP, NULL, NULL);
 #endif
+                               namei_cleanup_cnp(cnp);
                                return (ENOTCAPABLE);
                        }
                        while (*(cnp->cn_nameptr) == '/') {
@@ -296,11 +299,7 @@ namei(struct nameidata *ndp)
                ndp->ni_startdir = dp;
                error = lookup(ndp);
                if (error) {
-                       uma_zfree(namei_zone, cnp->cn_pnbuf);
-#ifdef DIAGNOSTIC
-                       cnp->cn_pnbuf = NULL;
-                       cnp->cn_nameptr = NULL;
-#endif
+                       namei_cleanup_cnp(cnp);
                        SDT_PROBE(vfs, namei, lookup, return, error, NULL, 0,
                            0, 0);
                        return (error);
@@ -310,11 +309,7 @@ namei(struct nameidata *ndp)
                 */
                if ((cnp->cn_flags & ISSYMLINK) == 0) {
                        if ((cnp->cn_flags & (SAVENAME | SAVESTART)) == 0) {
-                               uma_zfree(namei_zone, cnp->cn_pnbuf);
-#ifdef DIAGNOSTIC
-                               cnp->cn_pnbuf = NULL;
-                               cnp->cn_nameptr = NULL;
-#endif
+                               namei_cleanup_cnp(cnp);
                        } else
                                cnp->cn_flags |= HASBUF;
 
@@ -376,11 +371,7 @@ namei(struct nameidata *ndp)
                vput(ndp->ni_vp);
                dp = ndp->ni_dvp;
        }
-       uma_zfree(namei_zone, cnp->cn_pnbuf);
-#ifdef DIAGNOSTIC
-       cnp->cn_pnbuf = NULL;
-       cnp->cn_nameptr = NULL;
-#endif
+       namei_cleanup_cnp(cnp);
        vput(ndp->ni_vp);
        ndp->ni_vp = NULL;
        vrele(ndp->ni_dvp);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to