Module Name: src Committed By: riz Date: Thu May 17 18:12:13 UTC 2012
Modified Files: src/sys/kern [netbsd-6]: vfs_syscalls.c Log Message: Pull up following revision(s) (requested by rmind in ticket #246): sys/kern/vfs_syscalls.c: revision 1.455 do_open: move pathbuf destruction to the callers, thus simplify and fix a memory leak on error path. To generate a diff of this commit: cvs rdiff -u -r1.449 -r1.449.2.1 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.449 src/sys/kern/vfs_syscalls.c:1.449.2.1 --- src/sys/kern/vfs_syscalls.c:1.449 Sun Feb 12 13:12:45 2012 +++ src/sys/kern/vfs_syscalls.c Thu May 17 18:12:12 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.449 2012/02/12 13:12:45 martin Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.449.2.1 2012/05/17 18:12:12 riz Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.449 2012/02/12 13:12:45 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.449.2.1 2012/05/17 18:12:12 riz Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -1485,9 +1485,9 @@ do_open(lwp_t *l, struct pathbuf *pb, in return EINVAL; if ((error = fd_allocfile(&fp, &indx)) != 0) { - pathbuf_destroy(pb); return error; } + /* We're going to read cwdi->cwdi_cmask unlocked here. */ cmode = ((open_mode &~ cwdi->cwdi_cmask) & ALLPERMS) &~ S_ISTXT; NDINIT(&nd, LOOKUP, FOLLOW | TRYEMULROOT, pb); @@ -1499,18 +1499,15 @@ do_open(lwp_t *l, struct pathbuf *pb, in (error = fd_dupopen(l->l_dupfd, &indx, flags, error)) == 0) { *fd = indx; - pathbuf_destroy(pb); - return (0); + return 0; } if (error == ERESTART) error = EINTR; - pathbuf_destroy(pb); return error; } l->l_dupfd = 0; vp = nd.ni_vp; - pathbuf_destroy(pb); if ((error = open_setfp(l, fp, vp, indx, flags))) return error; @@ -1525,7 +1522,7 @@ int fd_open(const char *path, int open_flags, int open_mode, int *fd) { struct pathbuf *pb; - int oflags; + int error, oflags; oflags = FFLAGS(open_flags); if ((oflags & (FREAD | FWRITE)) == 0) @@ -1535,7 +1532,10 @@ fd_open(const char *path, int open_flags if (pb == NULL) return ENOMEM; - return do_open(curlwp, pb, open_flags, open_mode, fd); + error = do_open(curlwp, pb, open_flags, open_mode, fd); + pathbuf_destroy(pb); + + return error; } /* @@ -1555,18 +1555,17 @@ sys_open(struct lwp *l, const struct sys flags = FFLAGS(SCARG(uap, flags)); if ((flags & (FREAD | FWRITE)) == 0) - return (EINVAL); + return EINVAL; error = pathbuf_copyin(SCARG(uap, path), &pb); if (error) return error; error = do_open(l, pb, SCARG(uap, flags), SCARG(uap, mode), &result); - if (error) - return error; + pathbuf_destroy(pb); *retval = result; - return 0; + return error; } int