From dd03f8cae1fdb1cd2807ad90998d40ed9ad4029e Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 26 Jan 2017 22:09:37 +0100 Subject: [PATCH] lib: move at_close call in vty_stdio to end Since the at_close call for the stdio vty might exit() the process, move it to the end of the function, after freeing all memory. Signed-off-by: David Lamparter --- lib/vty.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/vty.c b/lib/vty.c index e70079c52d..9e0625e3cb 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -2227,6 +2227,7 @@ void vty_close (struct vty *vty) { int i; + bool was_stdio; /* Cancel threads.*/ if (vty->t_read) @@ -2254,7 +2255,7 @@ vty_close (struct vty *vty) if (vty->fd > 0) close (vty->fd); else - vty_stdio_reset (); + was_stdio = true; if (vty->buf) XFREE (MTYPE_VTY, vty->buf); @@ -2267,6 +2268,9 @@ vty_close (struct vty *vty) /* OK free vty. */ XFREE (MTYPE_VTY, vty); + + if (was_stdio) + vty_stdio_reset (); } /* When time out occur output message then close connection. */ -- 2.39.5