don't lock if ref is nil

Ensure that d.mu is only dereferenced if d is not-nil, to avoid a null
dereference panic.
This commit is contained in:
Mahmood Ali
2020-08-24 20:19:40 -04:00
parent d787c28de0
commit b84bd95b6a

View File

@@ -117,12 +117,13 @@ func NewAllocDir(logger hclog.Logger, allocDir string) *AllocDir {
// Copy an AllocDir and all of its TaskDirs. Returns nil if AllocDir is
// nil.
func (d *AllocDir) Copy() *AllocDir {
d.mu.RLock()
defer d.mu.RUnlock()
if d == nil {
return nil
}
d.mu.RLock()
defer d.mu.RUnlock()
dcopy := &AllocDir{
AllocDir: d.AllocDir,
SharedDir: d.SharedDir,