Behavior of perturbations of solitary and periodic waves on the surface of a heavy liquid