From 569efacf6636cd41c8173c390e9786e92872579f Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 3 May 2002 17:55:10 +0000 Subject: Fix a memory-leak when configuring a vnode backed md(4) device fails. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Submitted by: Martin Faxér MFC after: 4 weeks --- sys/dev/md/md.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'sys/dev/md') diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c index b80839f..2d27cb6 100644 --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -609,18 +609,6 @@ mdcreate_vnode(struct md_ioctl *mdio, struct thread *td) struct nameidata nd; int error, flags; - if (mdio->md_options & MD_AUTOUNIT) { - sc = mdnew(-1); - mdio->md_unit = sc->unit; - } else { - sc = mdnew(mdio->md_unit); - } - if (sc == NULL) - return (EBUSY); - - sc->type = MD_VNODE; - sc->flags = mdio->md_options & MD_FORCE; - flags = FREAD|FWRITE; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, mdio->md_file, td); error = vn_open(&nd, &flags, 0); @@ -628,7 +616,6 @@ mdcreate_vnode(struct md_ioctl *mdio, struct thread *td) if (error != EACCES && error != EPERM && error != EROFS) return (error); flags &= ~FWRITE; - sc->flags |= MD_READONLY; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, mdio->md_file, td); error = vn_open(&nd, &flags, 0); if (error) @@ -642,6 +629,22 @@ mdcreate_vnode(struct md_ioctl *mdio, struct thread *td) return (error ? error : EINVAL); } VOP_UNLOCK(nd.ni_vp, 0, td); + + if (mdio->md_options & MD_AUTOUNIT) { + sc = mdnew(-1); + mdio->md_unit = sc->unit; + } else { + sc = mdnew(mdio->md_unit); + } + if (sc == NULL) { + (void) vn_close(nd.ni_vp, flags, td->td_ucred, td); + return (EBUSY); + } + + sc->type = MD_VNODE; + sc->flags = mdio->md_options & MD_FORCE; + if (!(flags & FWRITE)) + sc->flags |= MD_READONLY; sc->secsize = DEV_BSIZE; sc->vnode = nd.ni_vp; -- cgit v1.1