Index: kernel/generic/src/ipc/kbox.c
===================================================================
--- kernel/generic/src/ipc/kbox.c	(revision 338a8382de09e384c0b79d87833774b803981ddf)
+++ kernel/generic/src/ipc/kbox.c	(revision 94f8e3c12f3631587fc47bc8a061c59efb915ec5)
@@ -46,4 +46,5 @@
 void ipc_kbox_cleanup(void)
 {
+	ipl_t ipl;
 	bool have_kb_thread;
 
@@ -64,4 +65,15 @@
 	 */
 	ipc_answerbox_slam_phones(&TASK->kernel_box, have_kb_thread);
+
+	/* 
+	 * If the task was being debugged, clean up debugging session.
+	 * This is necessarry as slamming the phones won't force
+	 * kbox thread to clean it up since sender != debugger.
+	 */
+	ipl = interrupts_disable();
+	spinlock_lock(&TASK->lock);
+	udebug_task_cleanup(TASK);
+	spinlock_unlock(&TASK->lock);
+	interrupts_restore(ipl);
 	
 	if (have_kb_thread) {
@@ -127,5 +139,10 @@
 				spinlock_lock(&TASK->answerbox.lock);
 				if (list_empty(&TASK->answerbox.connected_phones)) {
-					/* Last phone has been disconnected */
+					/*
+					 * Last phone has been disconnected.
+					 */
+
+					/* Detach thread so it gets freed. */
+					thread_detach(TASK->kb_thread);
 					TASK->kb_thread = NULL;
 					done = true;
