Material ejected in gamma-ray bursts may be source of heavy elements