From cdcfa4572f8fb61979636d32df38910b8105c6c5 Mon Sep 17 00:00:00 2001 From: vishalnayak Date: Tue, 30 Aug 2016 16:36:58 -0400 Subject: [PATCH] Address review feedback --- builtin/credential/approle/backend.go | 6 +++--- helper/locksutil/locks.go | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/builtin/credential/approle/backend.go b/builtin/credential/approle/backend.go index d4bbf84f6..3e96c3c38 100644 --- a/builtin/credential/approle/backend.go +++ b/builtin/credential/approle/backend.go @@ -61,13 +61,13 @@ func Backend(conf *logical.BackendConfig) (*backend, error) { salt: salt, // Create the map of locks to modify the registered roles - roleLocksMap: map[string]*sync.RWMutex{}, + roleLocksMap: make(map[string]*sync.RWMutex, 257), // Create the map of locks to modify the generated RoleIDs. - roleIDLocksMap: map[string]*sync.RWMutex{}, + roleIDLocksMap: make(map[string]*sync.RWMutex, 257), // Create the map of locks to modify the generated SecretIDs. - secretIDLocksMap: map[string]*sync.RWMutex{}, + secretIDLocksMap: make(map[string]*sync.RWMutex, 257), } // Create 256 locks each for managing RoleID and SecretIDs. This will avoid diff --git a/helper/locksutil/locks.go b/helper/locksutil/locks.go index d5fd4ed5d..e1cdce0b7 100644 --- a/helper/locksutil/locks.go +++ b/helper/locksutil/locks.go @@ -16,6 +16,10 @@ func CreateLocks(p map[string]*sync.RWMutex, count int64) error { return fmt.Errorf("invalid count: %d", count) } + if p == nil { + return fmt.Errorf("map of locks is not initialized") + } + for i := int64(0); i < count; i++ { p[fmt.Sprintf("%02x", i)] = &sync.RWMutex{} }