Add missing check on malloc allocation