kernel: Fix all leaks and cleanup