aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/md
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2002-05-03 17:55:10 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2002-05-03 17:55:10 +0000
commit9589c2561ceab4ce3962821fa9119a6a2482d3fd (patch)
tree78228e28fbb463d34dcd9ce4942138272bf5ce0d /sys/dev/md
parent263dc775f2e0a79a7e17bbfeff8e8d5729922b65 (diff)
downloadsrc-9589c2561ceab4ce3962821fa9119a6a2482d3fd.tar.gz
src-9589c2561ceab4ce3962821fa9119a6a2482d3fd.zip
Fix a memory-leak when configuring a vnode backed md(4) device fails.
Submitted by: Martin Faxér <gmh003532@brfmasthugget.se> MFC after: 4 weeks
Notes
Notes: svn path=/head/; revision=95991
Diffstat (limited to 'sys/dev/md')
-rw-r--r--sys/dev/md/md.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c
index b80839f7695e..2d27cb6aefee 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;