From: xinhui.pan Date: Mon, 28 Jul 2014 08:14:52 +0000 (+0800) Subject: tty/n_gsm.c: fix a memory leak in gsmld_open X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5a64096700dc9761b57e767c9f0b740eb2cb84dd;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git tty/n_gsm.c: fix a memory leak in gsmld_open If gsmld_attach_gsm fails, the gsm is not used anymore. tty core will not call gsmld_close to do the cleanup work. tty core just restore to the tty old ldisc. That always causes memory leak. Signed-off-by: xinhui.pan Reported-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index d5f578fe3fa6..152443ab1447 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2366,6 +2366,7 @@ static void gsmld_close(struct tty_struct *tty) static int gsmld_open(struct tty_struct *tty) { struct gsm_mux *gsm; + int ret; if (tty->ops->write == NULL) return -EINVAL; @@ -2380,7 +2381,13 @@ static int gsmld_open(struct tty_struct *tty) /* Attach the initial passive connection */ gsm->encoding = 1; - return gsmld_attach_gsm(tty, gsm); + + ret = gsmld_attach_gsm(tty, gsm); + if (ret != 0) { + gsm_cleanup_mux(gsm); + mux_put(gsm); + } + return ret; } /**