Re: [PATCH] Prevent memory leak in devpts

Olaf Kirch
2004-08-25T13:41:38Z

[-- 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);