DEBUG: Pass a temporary copy of refname to each_ref_fn

This should allow valgrind to find users who retain a reference.
DEBUG: Also copy sha1