pkg/build: shutdown bazel in case of errors too
diff --git a/pkg/build/gvisor.go b/pkg/build/gvisor.go
index 439e64c..a2a856d 100644
--- a/pkg/build/gvisor.go
+++ b/pkg/build/gvisor.go
@@ -15,6 +15,8 @@
 
 func (gvisor gvisor) build(targetArch, vmType, kernelDir, outputDir, compiler, userspaceDir,
 	cmdlineFile, sysctlFile string, config []byte) error {
+	// Bring down bazel daemon right away. We don't need it running and consuming memory.
+	defer osutil.RunCmd(10*time.Minute, kernelDir, compiler, "shutdown")
 	outBinary := ""
 	args := []string{"build", "--verbose_failures"}
 	if strings.Contains(" "+string(config)+" ", " -race ") {
@@ -31,7 +33,6 @@
 	if err := osutil.CopyFile(outBinary, filepath.Join(outputDir, "image")); err != nil {
 		return err
 	}
-	osutil.RunCmd(10*time.Minute, kernelDir, compiler, "shutdown")
 	return nil
 }