comparison common-session.c @ 1040:2b4fd440399d

Free memory before exiting. Based on patch from Thorsten Horstmann. Client side is not complete.
author Matt Johnston <matt@ucc.asn.au>
date Tue, 24 Feb 2015 22:01:33 +0800
parents d3925ed45a85
children 3fb883a6aa81
comparison
equal deleted inserted replaced
1039:d0e6dd5af46e 1040:2b4fd440399d
238 } /* for(;;) */ 238 } /* for(;;) */
239 239
240 /* Not reached */ 240 /* Not reached */
241 } 241 }
242 242
243 static void cleanup_buf(buffer **buf) {
244 if (!*buf) {
245 return;
246 }
247 buf_burn(*buf);
248 buf_free(*buf);
249 *buf = NULL;
250 }
251
243 /* clean up a session on exit */ 252 /* clean up a session on exit */
244 void session_cleanup() { 253 void session_cleanup() {
245 254
246 TRACE(("enter session_cleanup")) 255 TRACE(("enter session_cleanup"))
247 256
254 if (ses.extra_session_cleanup) { 263 if (ses.extra_session_cleanup) {
255 ses.extra_session_cleanup(); 264 ses.extra_session_cleanup();
256 } 265 }
257 266
258 chancleanup(); 267 chancleanup();
259 268
260 /* Cleaning up keys must happen after other cleanup 269 /* Most dropbear functions are unsafe to run after this point */
261 functions which might queue packets */ 270 #ifdef DROPBEAR_CLEANUP
262 if (ses.session_id) { 271 /* listeners call cleanup functions, this should occur before
263 buf_burn(ses.session_id); 272 other session state is freed. */
264 buf_free(ses.session_id); 273 remove_all_listeners();
265 ses.session_id = NULL; 274
266 } 275 while (!isempty(&ses.writequeue)) {
267 if (ses.hash) { 276 buf_free(dequeue(&ses.writequeue));
268 buf_burn(ses.hash); 277 }
269 buf_free(ses.hash); 278
270 ses.hash = NULL; 279 m_free(ses.remoteident);
271 } 280 m_free(ses.authstate.pw_dir);
281 m_free(ses.authstate.pw_name);
282 m_free(ses.authstate.pw_shell);
283 m_free(ses.authstate.pw_passwd);
284 m_free(ses.authstate.username);
285 #endif
286
287 cleanup_buf(&ses.session_id);
288 cleanup_buf(&ses.hash);
289 cleanup_buf(&ses.payload);
290 cleanup_buf(&ses.readbuf);
291 cleanup_buf(&ses.writepayload);
292
272 m_burn(ses.keys, sizeof(struct key_context)); 293 m_burn(ses.keys, sizeof(struct key_context));
273 m_free(ses.keys); 294 m_free(ses.keys);
274 295
275 TRACE(("leave session_cleanup")) 296 TRACE(("leave session_cleanup"))
276 } 297 }