TTY: pty, fix tty buffers leak
authorJiri Slaby <jslaby@suse.cz>
Thu, 15 Nov 2012 08:49:49 +0000 (09:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 16 Nov 2012 01:18:55 +0000 (17:18 -0800)
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>
drivers/tty/pty.c
drivers/tty/tty_port.c

index 0ce0b3ec2bb026905a32414dfe880d26e529499d..a541ec875932bdddc9329a64a5d1bc3b977584e2 100644 (file)
@@ -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 */
index 416b42f7c346680067ea6eb8d4679421cf5596c8..fdc42c2d565f4f70fc9495b99a025a37894e9215 100644 (file)
@@ -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);