improve error handling in malloc tutorial example