diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index a2b28c696..89e75c689 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -228,7 +228,8 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
 			v->s = s;
 		}
 		else if (!strcmp(name, "objectname:short")) {
-			v->s = find_unique_abbrev(obj->sha1, DEFAULT_ABBREV);
+			v->s = xstrdup(find_unique_abbrev(obj->sha1,
+							  DEFAULT_ABBREV));
 		}
 	}
 }