Add error check after malloc.