public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Olaf Kirch <okir@suse.de>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Prevent memory leak in devpts
Date: Wed, 25 Aug 2004 12:52:53 +0200	[thread overview]
Message-ID: <20040825105252.GA24572@suse.de> (raw)

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

             reply	other threads:[~2004-08-25 10:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-25 10:52 Olaf Kirch [this message]
2004-08-25 13:41 ` [PATCH] Prevent memory leak in devpts Olaf Kirch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040825105252.GA24572@suse.de \
    --to=okir@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox