[PATCH] Prevent memory leak in devpts

Olaf Kirch
2004-08-25T10:52:56Z

[-- Attachment #1: Type: text/plain, Size: 652 bytes --]

Hi,

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.

The attached patch does this.

Olaf
--
Olaf Kirch | The Hardware Gods hate me.
okir@suse.de |
---------------+

[-- Attachment #2: devpts-dentry-refcount --]
[-- Type: text/plain, Size: 326 bytes --]

Index: v268/fs/devpts/inode.c
===================================================================
--- v268.orig/fs/devpts/inode.c
+++ v268/fs/devpts/inode.c
@@ -183,6 +183,7 @@ struct tty_struct *devpts_get_tty(int nu
dentry->d_inode->u.generic_ip;

up(&devpts_root->d_inode->i_sem);
+ dput(dentry);

return tty;
}