Remove trailing whitespace, add checks for malloc return value.