Skip to content

Commit

Permalink
TTY: pty, fix tty buffers leak
Browse files Browse the repository at this point in the history
After commit "TTY: move tty buffers to tty_port", the tty buffers are
not freed in some drivers. This is because tty_port_destructor is not
called whenever a tty_port is freed. This was an assumption I counted
with but was unfortunately untrue. So fix the drivers to fulfil this
assumption.

PTY is one of those, here we just need to use tty_port_put instead of
kfree. (Assuming tty_port_destructor does not need port->ops to be set
which we change here too.)

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jiri Slaby authored and Greg Kroah-Hartman committed Nov 16, 2012
1 parent 7342c59 commit 81c7983
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/tty/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ static void pty_unix98_shutdown(struct tty_struct *tty)
static void pty_cleanup(struct tty_struct *tty)
{
tty->port->itty = NULL;
kfree(tty->port);
tty_port_put(tty->port);
}

/* Traditional BSD devices */
Expand Down
2 changes: 1 addition & 1 deletion drivers/tty/tty_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static void tty_port_destructor(struct kref *kref)
if (port->xmit_buf)
free_page((unsigned long)port->xmit_buf);
tty_buffer_free_all(port);
if (port->ops->destruct)
if (port->ops && port->ops->destruct)
port->ops->destruct(port);
else
kfree(port);
Expand Down

0 comments on commit 81c7983

Please sign in to comment.