Added a safe_malloc and removed the cast when using it.