Index: kernel/generic/src/proc/thread.c
===================================================================
--- kernel/generic/src/proc/thread.c	(revision 4365d108fca11d735aaf46f7098b7f1d5c2cbb52)
+++ kernel/generic/src/proc/thread.c	(revision e8a0b90b4a2726b532a39fb80b80662f5bed01e9)
@@ -300,4 +300,13 @@
 		task_destroy(t->task);
 	
+	/*
+	 * If the thread had a userspace context, free up its kernel_uarg
+	 * structure.
+	 */
+	if (t->flags & THREAD_FLAG_USPACE) {
+		ASSERT(t->thread_arg);
+		free(t->thread_arg);
+	}
+
 	slab_free(thread_slab, t);
 }
@@ -313,5 +322,5 @@
  * @param name      Symbolic name.
  * @param uncounted Thread's accounting doesn't affect accumulated task
- * 	 accounting.
+ * 		    accounting.
  *
  * @return New thread's structure on success, NULL on failure.
@@ -319,5 +328,5 @@
  */
 thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,
-	int flags, char *name, bool uncounted)
+    int flags, char *name, bool uncounted)
 {
 	thread_t *t;
@@ -638,5 +647,6 @@
  *
  */
-unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name, thread_id_t *uspace_thread_id)
+unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name,
+    thread_id_t *uspace_thread_id)
 {
 	thread_t *t;
@@ -661,6 +671,6 @@
 		thread_ready(t);
 		if (uspace_thread_id != NULL)
-			return (unative_t) copy_to_uspace(uspace_thread_id, &t->tid,
-			    sizeof(t->tid));
+			return (unative_t) copy_to_uspace(uspace_thread_id,
+			    &t->tid, sizeof(t->tid));
 		else
 			return 0;
