remove unnecessary cast
handle `malloc` failure