From 8f75c1c9a5ce6747279a75bbe73e4aa79418d0cd Mon Sep 17 00:00:00 2001 From: Joe Selman Date: Wed, 19 Jul 2017 13:19:27 -0700 Subject: [PATCH] Fix bug where range variable is improperly dereferenced (#217) * Fix bug where range variable is improperly dereferenced * Add comment explaining why a value is copied --- google/metadata.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/google/metadata.go b/google/metadata.go index 7e20e58f134..5dc63a67185 100644 --- a/google/metadata.go +++ b/google/metadata.go @@ -103,7 +103,10 @@ func expandComputeMetadata(m map[string]string) []*compute.MetadataItems { idx := 0 for key, value := range m { - metadata[idx] = &compute.MetadataItems{Key: key, Value: &value} + // Make a copy of value as we need a ptr type; if we directly use 'value' then all items will reference the same + // memory address + vtmp := value + metadata[idx] = &compute.MetadataItems{Key: key, Value: &vtmp} idx++ }