Use safe_malloc and/or check returns from malloc (Jim Meyering).