* [PATCH] Prevent memory leak in devpts
@ 2004-08-25 10:52 Olaf Kirch
2004-08-25 13:41 ` Olaf Kirch
0 siblings, 1 reply; 2+ messages in thread
From: Olaf Kirch @ 2004-08-25 10:52 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel
[-- 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;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Prevent memory leak in devpts
2004-08-25 10:52 [PATCH] Prevent memory leak in devpts Olaf Kirch
@ 2004-08-25 13:41 ` Olaf Kirch
0 siblings, 0 replies; 2+ messages in thread
From: Olaf Kirch @ 2004-08-25 13:41 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 249 bytes --]
This is a lame self-followup. Kurt Garloff pointed out that I should
obviously handle the error case more gracefully than by oopsing.
Improved patch attached.
Olaf
--
Olaf Kirch | The Hardware Gods hate me.
okir@suse.de |
---------------+
[-- Attachment #2: devpts-dentry-refcount --]
[-- Type: text/plain, Size: 572 bytes --]
Index: linux-2.6.5/fs/devpts/inode.c
===================================================================
--- linux-2.6.5.orig/fs/devpts/inode.c
+++ linux-2.6.5/fs/devpts/inode.c
@@ -178,9 +178,13 @@ struct tty_struct *devpts_get_tty(int nu
{
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);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-08-25 13:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-25 10:52 [PATCH] Prevent memory leak in devpts Olaf Kirch
2004-08-25 13:41 ` Olaf Kirch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox