diff options
author | Matt Johnston <matt@ucc.asn.au> | 2015-02-24 22:01:33 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2015-02-24 22:01:33 +0800 |
commit | 21bed0d21aa765c7796d977fcb36902399e97242 (patch) | |
tree | 9bcdd6ef0ba69f74b2b8f8675b3bca414ad3e4c1 /common-session.c | |
parent | 4b1f5ec7c29043a7d4ec0dd75f10479ed909a187 (diff) |
Free memory before exiting. Based on patch from Thorsten Horstmann.
Client side is not complete.
Diffstat (limited to 'common-session.c')
-rw-r--r-- | common-session.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/common-session.c b/common-session.c index d820d64..a225b21 100644 --- a/common-session.c +++ b/common-session.c @@ -240,6 +240,15 @@ void session_loop(void(*loophandler)()) { /* Not reached */ } +static void cleanup_buf(buffer **buf) { + if (!*buf) { + return; + } + buf_burn(*buf); + buf_free(*buf); + *buf = NULL; +} + /* clean up a session on exit */ void session_cleanup() { @@ -256,19 +265,31 @@ void session_cleanup() { } chancleanup(); - - /* Cleaning up keys must happen after other cleanup - functions which might queue packets */ - if (ses.session_id) { - buf_burn(ses.session_id); - buf_free(ses.session_id); - ses.session_id = NULL; - } - if (ses.hash) { - buf_burn(ses.hash); - buf_free(ses.hash); - ses.hash = NULL; + + /* Most dropbear functions are unsafe to run after this point */ +#ifdef DROPBEAR_CLEANUP + /* listeners call cleanup functions, this should occur before + other session state is freed. */ + remove_all_listeners(); + + while (!isempty(&ses.writequeue)) { + buf_free(dequeue(&ses.writequeue)); } + + m_free(ses.remoteident); + m_free(ses.authstate.pw_dir); + m_free(ses.authstate.pw_name); + m_free(ses.authstate.pw_shell); + m_free(ses.authstate.pw_passwd); + m_free(ses.authstate.username); +#endif + + cleanup_buf(&ses.session_id); + cleanup_buf(&ses.hash); + cleanup_buf(&ses.payload); + cleanup_buf(&ses.readbuf); + cleanup_buf(&ses.writepayload); + m_burn(ses.keys, sizeof(struct key_context)); m_free(ses.keys); |