Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
636a2ef2
Unverified
Commit
636a2ef2
authored
Oct 25, 2019
by
Stéphane Graber
Committed by
GitHub
Oct 25, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3171 from brauner/bugfixes
terminal: prevent memory leak for lxc_terminal_state
parents
a86690e0
28327a43
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
19 deletions
+25
-19
terminal.c
src/lxc/terminal.c
+22
-16
terminal.h
src/lxc/terminal.h
+3
-3
No files found.
src/lxc/terminal.c
View file @
636a2ef2
...
@@ -115,10 +115,10 @@ int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
...
@@ -115,10 +115,10 @@ int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
struct
lxc_terminal_state
*
lxc_terminal_signal_init
(
int
srcfd
,
int
dstfd
)
struct
lxc_terminal_state
*
lxc_terminal_signal_init
(
int
srcfd
,
int
dstfd
)
{
{
int
ret
;
__do_free
struct
lxc_terminal_state
*
ts
=
NULL
;
bool
istty
=
false
;
bool
istty
=
false
;
int
ret
;
sigset_t
mask
;
sigset_t
mask
;
struct
lxc_terminal_state
*
ts
;
ts
=
malloc
(
sizeof
(
*
ts
));
ts
=
malloc
(
sizeof
(
*
ts
));
if
(
!
ts
)
if
(
!
ts
)
...
@@ -177,16 +177,23 @@ on_error:
...
@@ -177,16 +177,23 @@ on_error:
return
ts
;
return
ts
;
}
}
void
lxc_terminal_signal_fini
(
struct
lxc_terminal
_state
*
ts
)
void
lxc_terminal_signal_fini
(
struct
lxc_terminal
*
terminal
)
{
{
if
(
ts
->
sigfd
>=
0
)
{
struct
lxc_terminal_state
*
state
=
terminal
->
tty_state
;
close
(
ts
->
sigfd
);
if
(
pthread_sigmask
(
SIG_SETMASK
,
&
ts
->
oldmask
,
NULL
)
<
0
)
if
(
!
terminal
->
tty_state
)
return
;
state
=
terminal
->
tty_state
;
if
(
state
->
sigfd
>=
0
)
{
close
(
state
->
sigfd
);
if
(
pthread_sigmask
(
SIG_SETMASK
,
&
state
->
oldmask
,
NULL
)
<
0
)
SYSWARN
(
"Failed to restore signal mask"
);
SYSWARN
(
"Failed to restore signal mask"
);
}
}
free
(
ts
);
free
(
terminal
->
tty_state
);
terminal
->
tty_state
=
NULL
;
}
}
static
int
lxc_terminal_truncate_log_file
(
struct
lxc_terminal
*
terminal
)
static
int
lxc_terminal_truncate_log_file
(
struct
lxc_terminal
*
terminal
)
...
@@ -348,10 +355,7 @@ int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
...
@@ -348,10 +355,7 @@ int lxc_terminal_io_cb(int fd, uint32_t events, void *data,
if
(
fd
==
terminal
->
master
)
{
if
(
fd
==
terminal
->
master
)
{
terminal
->
master
=
-
EBADF
;
terminal
->
master
=
-
EBADF
;
}
else
if
(
fd
==
terminal
->
peer
)
{
}
else
if
(
fd
==
terminal
->
peer
)
{
if
(
terminal
->
tty_state
)
{
lxc_terminal_signal_fini
(
terminal
);
lxc_terminal_signal_fini
(
terminal
->
tty_state
);
terminal
->
tty_state
=
NULL
;
}
terminal
->
peer
=
-
EBADF
;
terminal
->
peer
=
-
EBADF
;
}
else
{
}
else
{
ERROR
(
"Handler received unexpected file descriptor"
);
ERROR
(
"Handler received unexpected file descriptor"
);
...
@@ -499,10 +503,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
...
@@ -499,10 +503,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
static
void
lxc_terminal_peer_proxy_free
(
struct
lxc_terminal
*
terminal
)
static
void
lxc_terminal_peer_proxy_free
(
struct
lxc_terminal
*
terminal
)
{
{
if
(
terminal
->
tty_state
)
{
lxc_terminal_signal_fini
(
terminal
);
lxc_terminal_signal_fini
(
terminal
->
tty_state
);
terminal
->
tty_state
=
NULL
;
}
close
(
terminal
->
proxy
.
master
);
close
(
terminal
->
proxy
.
master
);
terminal
->
proxy
.
master
=
-
1
;
terminal
->
proxy
.
master
=
-
1
;
...
@@ -1018,6 +1019,9 @@ int lxc_console(struct lxc_container *c, int ttynum,
...
@@ -1018,6 +1019,9 @@ int lxc_console(struct lxc_container *c, int ttynum,
struct
lxc_epoll_descr
descr
;
struct
lxc_epoll_descr
descr
;
struct
termios
oldtios
;
struct
termios
oldtios
;
struct
lxc_terminal_state
*
ts
;
struct
lxc_terminal_state
*
ts
;
struct
lxc_terminal
terminal
=
{
.
tty_state
=
NULL
,
};
int
istty
=
0
;
int
istty
=
0
;
ttyfd
=
lxc_cmd_console
(
c
->
name
,
&
ttynum
,
&
masterfd
,
c
->
config_path
);
ttyfd
=
lxc_cmd_console
(
c
->
name
,
&
ttynum
,
&
masterfd
,
c
->
config_path
);
...
@@ -1033,6 +1037,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
...
@@ -1033,6 +1037,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
ret
=
-
1
;
ret
=
-
1
;
goto
close_fds
;
goto
close_fds
;
}
}
terminal
.
tty_state
=
ts
;
ts
->
escape
=
escape
;
ts
->
escape
=
escape
;
ts
->
stdoutfd
=
stdoutfd
;
ts
->
stdoutfd
=
stdoutfd
;
...
@@ -1107,7 +1112,7 @@ close_mainloop:
...
@@ -1107,7 +1112,7 @@ close_mainloop:
lxc_mainloop_close
(
&
descr
);
lxc_mainloop_close
(
&
descr
);
sigwinch_fini:
sigwinch_fini:
lxc_terminal_signal_fini
(
ts
);
lxc_terminal_signal_fini
(
&
terminal
);
close_fds:
close_fds:
close
(
masterfd
);
close
(
masterfd
);
...
@@ -1171,6 +1176,7 @@ void lxc_terminal_conf_free(struct lxc_terminal *terminal)
...
@@ -1171,6 +1176,7 @@ void lxc_terminal_conf_free(struct lxc_terminal *terminal)
free
(
terminal
->
path
);
free
(
terminal
->
path
);
if
(
terminal
->
buffer_size
>
0
&&
terminal
->
ringbuf
.
addr
)
if
(
terminal
->
buffer_size
>
0
&&
terminal
->
ringbuf
.
addr
)
lxc_ringbuf_release
(
&
terminal
->
ringbuf
);
lxc_ringbuf_release
(
&
terminal
->
ringbuf
);
lxc_terminal_signal_fini
(
terminal
);
}
}
int
lxc_terminal_map_ids
(
struct
lxc_conf
*
c
,
struct
lxc_terminal
*
terminal
)
int
lxc_terminal_map_ids
(
struct
lxc_conf
*
c
,
struct
lxc_terminal
*
terminal
)
...
...
src/lxc/terminal.h
View file @
636a2ef2
...
@@ -265,8 +265,8 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
...
@@ -265,8 +265,8 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
/**
/**
* lxc_terminal_signal_fini: uninstall signal handler
* lxc_terminal_signal_fini: uninstall signal handler
*
*
* @t
s
* @t
erminal
* - the lxc_terminal
_state returned by lxc_terminal_signal_init
* - the lxc_terminal
*
*
* Restore the saved signal handler that was in effect at the time
* Restore the saved signal handler that was in effect at the time
* lxc_terminal_signal_init() was called.
* lxc_terminal_signal_init() was called.
...
@@ -274,7 +274,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
...
@@ -274,7 +274,7 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
* Must be called with process_lock held to protect the lxc_ttys list, or
* Must be called with process_lock held to protect the lxc_ttys list, or
* from a non-threaded context.
* from a non-threaded context.
*/
*/
extern
void
lxc_terminal_signal_fini
(
struct
lxc_terminal
_state
*
ts
);
extern
void
lxc_terminal_signal_fini
(
struct
lxc_terminal
*
terminal
);
extern
int
lxc_terminal_write_ringbuffer
(
struct
lxc_terminal
*
terminal
);
extern
int
lxc_terminal_write_ringbuffer
(
struct
lxc_terminal
*
terminal
);
extern
int
lxc_terminal_create_log_file
(
struct
lxc_terminal
*
terminal
);
extern
int
lxc_terminal_create_log_file
(
struct
lxc_terminal
*
terminal
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment