Commit 8cc42321 authored by Olaf Kirch's avatar Olaf Kirch Committed by Linus Torvalds

[PATCH] Prevent memory leak in devpts

There is a dentry refcount leak in devpts_get_tty.

struct tty_struct *devpts_get_tty(int number)
{
        struct dentry *dentry = get_node(number);
        struct tty_struct *tty;

        tty = (IS_ERR(dentry) || !dentry->d_inode) ? NULL :
                        dentry->d_inode->u.generic_ip;

        up(&devpts_root->d_inode->i_sem);
        return tty;
}

The get_node function does a lookup on /dev/pts/<number> and returns the
dentry, taking a reference.  We should dput the dentry after extracting the
tty pointer.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent b13b24e7
......@@ -179,8 +179,12 @@ struct tty_struct *devpts_get_tty(int number)
struct dentry *dentry = get_node(number);
struct tty_struct *tty;
tty = (IS_ERR(dentry) || !dentry->d_inode) ? NULL :
dentry->d_inode->u.generic_ip;
tty = NULL;
if (!IS_ERR(dentry)) {
if (dentry->d_inode)
tty = dentry->d_inode->u.generic_ip;
dput(dentry);
}
up(&devpts_root->d_inode->i_sem);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment