Index: kernel/generic/src/ipc/irq.c
===================================================================
--- kernel/generic/src/ipc/irq.c	(revision 472d813eb1dc68bae20fc6383ca3221f169fd0b7)
+++ kernel/generic/src/ipc/irq.c	(revision b40ea022046a3632a64eb4480d283e707a9fd0d7)
@@ -358,7 +358,4 @@
 	ASSERT(irq->notif_cfg.answerbox == box);
 	
-	/* Free up the pseudo code and associated structures. */
-	code_free(irq->notif_cfg.code);
-	
 	/* Remove the IRQ from the answerbox's list. */
 	list_remove(&irq->notif_cfg.link);
@@ -378,4 +375,7 @@
 	irq_spinlock_unlock(&box->irq_lock, false);
 	irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
+	
+	/* Free up the pseudo code and associated structures. */
+	code_free(irq->notif_cfg.code);
 	
 	/* Free up the IRQ structure. */
@@ -425,7 +425,4 @@
 		list_remove(&irq->notif_cfg.link);
 		
-		/* Free up the pseudo code and associated structures. */
-		code_free(irq->notif_cfg.code);
-		
 		/*
 		 * We need to drop the IRQ lock now because hash_table_remove()
@@ -439,6 +436,17 @@
 		/* Remove from the hash table. */
 		hash_table_remove(&irq_uspace_hash_table, key, 2);
-		
+
+		/*
+		 * Release both locks so that we can free the pseudo code.
+		 */
+		irq_spinlock_unlock(&box->irq_lock, false);
+		irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
+
+		code_free(irq->notif_cfg.code);
 		free(irq);
+		
+		/* Reacquire both locks before taking another round. */
+		irq_spinlock_lock(&irq_uspace_hash_table_lock, true);
+		irq_spinlock_lock(&box->irq_lock, false);
 	}
 	
