Avoid race condition in isInnerShortcode
authorbep <bjorn.erik.pedersen@gmail.com>
Fri, 20 Feb 2015 16:41:37 +0000 (17:41 +0100)
committerbep <bjorn.erik.pedersen@gmail.com>
Fri, 20 Feb 2015 16:41:37 +0000 (17:41 +0100)
As reported by Go's race detector.

See #917

hugolib/shortcode.go

index 0bdfcd5a5a7f6dbb31abd3ec89b28afc05094d68..41560c0f41ccdfcfc50b2e2ea1ae14e0ee2dfe60 100644 (file)
@@ -160,11 +160,10 @@ func isInnerShortcode(t *template.Template) bool {
                return m
        }
 
-       match, _ := regexp.MatchString("{{.*?\\.Inner.*?}}", t.Tree.Root.String())
-
        isInnerShortcodeCache.Lock()
+       defer isInnerShortcodeCache.Unlock()
+       match, _ := regexp.MatchString("{{.*?\\.Inner.*?}}", t.Tree.Root.String())
        isInnerShortcodeCache.m[t.Name()] = match
-       isInnerShortcodeCache.Unlock()
 
        return match
 }