From 23be6e16ab7b8e659667c21fe3ec37d36dbb3b24 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Fri, 13 Apr 2018 18:35:25 -0700 Subject: [PATCH] Fix plugin loading Due to an interaction between pointers and go's `range` operator, we would end up always returning the last plugin in a user's plugin cache, instead of the right value. We now save the current plugin into a local, so if we end up taking the address the right thing will happen. Fixes #1196 --- pkg/workspace/plugins.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/workspace/plugins.go b/pkg/workspace/plugins.go index 9c5304d74..3980e6ee6 100644 --- a/pkg/workspace/plugins.go +++ b/pkg/workspace/plugins.go @@ -295,7 +295,10 @@ func GetPluginPath(kind PluginKind, name string, version *semver.Version) (strin return "", "", errors.Wrapf(err, "loading plugin list") } var match *PluginInfo - for _, plugin := range plugins { + for _, cur := range plugins { + // Since the value of cur changes as we iterate, we can't save a pointer to it. So let's have a local that + // we can take a pointer to if this plugin is the best match yet. + plugin := cur if plugin.Kind == kind && plugin.Name == name { // Always pick the most recent version of the plugin available. Even if this is an exact match, we // keep on searching just in case there's a newer version available.