From 7476f7e87de6ab6ceabe61e71968974f74476fec Mon Sep 17 00:00:00 2001 From: Ian Dowse Date: Tue, 4 Sep 2001 19:03:47 +0000 Subject: [PATCH] Fix a memory leak in __getcwd() that can occur after a filesystem has been forcibly unmounted. If the filesystem root vnode is reached and it has no associated mountpoint (vp->v_mount == NULL), __getcwd would return without freeing 'buf'. Add the missing free() call. PR: kern/30306 Submitted by: Mike Potanin MFC after: 1 week --- sys/kern/vfs_cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index ceb3c7245bcd..af3035a4cfbe 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -687,8 +687,10 @@ __getcwd(p, uap) slash_prefixed = 0; for (vp = fdp->fd_cdir; vp != fdp->fd_rdir && vp != rootvnode;) { if (vp->v_flag & VROOT) { - if (vp->v_mount == NULL) /* forced unmount */ + if (vp->v_mount == NULL) { /* forced unmount */ + free(buf, M_TEMP); return (EBADF); + } vp = vp->v_mount->mnt_vnodecovered; continue; }