aboutsummaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-02-06 15:40:41 -0800
committerColin Cross <ccross@android.com>2017-02-06 15:45:16 -0800
commitc0d58b4a0fa6ecd8cfc5e2cb15eabca29b9742a6 (patch)
tree1902fdb860082e6bae95e4f06b49b2a52e950b6a /android
parentc821042c3f9f719f0de303d337d254345543b885 (diff)
downloadbuild_soong-c0d58b4a0fa6ecd8cfc5e2cb15eabca29b9742a6.tar.gz
build_soong-c0d58b4a0fa6ecd8cfc5e2cb15eabca29b9742a6.tar.bz2
build_soong-c0d58b4a0fa6ecd8cfc5e2cb15eabca29b9742a6.zip
Fix envDeps initialization and locking
If Config.GetEnv was called when envDeps was uninitialized (for example in a test) it would panic, which if recovered (for example in a test) would cause it to continue without unlocking the mutex, and could later deadlock. Fix the initialization by initializing in GetEnv if necessary, and use defer to avoid holding the mutex after a panic. Test: soong tests Change-Id: I453522faaf47ff6fbc4702345cfe177100bdc522
Diffstat (limited to 'android')
-rw-r--r--android/config.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/android/config.go b/android/config.go
index 36034775..76635b39 100644
--- a/android/config.go
+++ b/android/config.go
@@ -177,7 +177,6 @@ func NewConfig(srcDir, buildDir string) (Config, error) {
srcDir: srcDir,
buildDir: buildDir,
- envDeps: make(map[string]string),
deviceConfig: &deviceConfig{},
}
@@ -281,6 +280,10 @@ func (c *config) Getenv(key string) string {
var val string
var exists bool
c.envLock.Lock()
+ defer c.envLock.Unlock()
+ if c.envDeps == nil {
+ c.envDeps = make(map[string]string)
+ }
if val, exists = c.envDeps[key]; !exists {
if c.envFrozen {
panic("Cannot access new environment variables after envdeps are frozen")
@@ -288,7 +291,6 @@ func (c *config) Getenv(key string) string {
val = os.Getenv(key)
c.envDeps[key] = val
}
- c.envLock.Unlock()
return val
}
@@ -312,8 +314,8 @@ func (c *config) IsEnvFalse(key string) bool {
func (c *config) EnvDeps() map[string]string {
c.envLock.Lock()
+ defer c.envLock.Unlock()
c.envFrozen = true
- c.envLock.Unlock()
return c.envDeps
}