The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/1633

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
This patch fix the memory leak of 'lxc_tty_state' while `lxc_console_sigwinch_init` returned` lxc_tty_state*` with the sigfd is -1. We did not call the `lxc_console_sigwinch_fini` to release the ` lxc_tty_state*` memory, so the memory had been lost.

Signed-off-by: Li Feng <[email protected]>
From 0e6da90bc0f455c73ebb7e0b6da519146cb9aefb Mon Sep 17 00:00:00 2001
From: Li Feng <[email protected]>
Date: Wed, 21 Jun 2017 13:38:06 +0800
Subject: [PATCH] Fix memory leak of 'lxc_tty_state'

Signed-off-by: Li Feng <[email protected]>
---
 src/lxc/console.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/lxc/console.c b/src/lxc/console.c
index 803c64f5c..666754d27 100755
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -135,6 +135,7 @@ struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, 
int dstfd)
        if (sigprocmask(SIG_BLOCK, &mask, &ts->oldmask)) {
                SYSERROR("failed to block SIGWINCH");
                ts->sigfd = -1;
+               lxc_list_del(&ts->node);
                return ts;
        }
 
@@ -143,6 +144,7 @@ struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, 
int dstfd)
                SYSERROR("failed to create signal fd");
                sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
                ts->sigfd = -1;
+               lxc_list_del(&ts->node);
                return ts;
        }
 
@@ -152,11 +154,12 @@ struct lxc_tty_state *lxc_console_sigwinch_init(int 
srcfd, int dstfd)
 
 void lxc_console_sigwinch_fini(struct lxc_tty_state *ts)
 {
-       if (ts->sigfd >= 0)
+       if (ts->sigfd >= 0) {
                close(ts->sigfd);
+               lxc_list_del(&ts->node);
+               sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
+       }
 
-       lxc_list_del(&ts->node);
-       sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
        free(ts);
 }
 
@@ -297,7 +300,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
 
 static void lxc_console_peer_proxy_free(struct lxc_console *console)
 {
-       if (console->tty_state && console->tty_state->sigfd != -1) {
+       if (console->tty_state) {
                lxc_console_sigwinch_fini(console->tty_state);
                console->tty_state = NULL;
        }
@@ -750,8 +753,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
 err4:
        lxc_mainloop_close(&descr);
 err3:
-       if (ts->sigfd != -1)
-               lxc_console_sigwinch_fini(ts);
+       lxc_console_sigwinch_fini(ts);
 err2:
        close(masterfd);
        close(ttyfd);
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to