From: Bjørn Erik Pedersen Date: Fri, 31 Mar 2017 08:40:33 +0000 (+0200) Subject: tplimpl: Fix map data race in URLLock X-Git-Tag: v0.20~55 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=42a4f6f9cbefb56698b9a4274473020188031754;p=brevno-suite%2Fhugo tplimpl: Fix map data race in URLLock --- diff --git a/tpl/tplimpl/template_resources.go b/tpl/tplimpl/template_resources.go index f10aa72e..cfec816a 100644 --- a/tpl/tplimpl/template_resources.go +++ b/tpl/tplimpl/template_resources.go @@ -46,12 +46,17 @@ type remoteLock struct { // URLLock locks an URL during download func (l *remoteLock) URLLock(url string) { + var ( + lock *sync.Mutex + ok bool + ) l.Lock() - if _, ok := l.m[url]; !ok { - l.m[url] = &sync.Mutex{} + if lock, ok = l.m[url]; !ok { + lock = &sync.Mutex{} + l.m[url] = lock } l.Unlock() - l.m[url].Lock() + lock.Lock() } // URLUnlock unlocks an URL when the download has been finished. Use only in defer calls.