hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 128f14efad90886ffef37c01ac1e20436a732f97
parent 34ee27a78b9e2b5f475d44253ae234067b76cc6e
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Wed, 13 Jun 2018 08:57:26 +0200

hugolib: Reset the global pages cache on server rebuilds

In Hugo 0.42, this could lead to errors of type `runtime error: invalid memory address or nil pointer dereference` in some rare situations.

Note that this was also an issue before 0.42, but the symptom was then potentially stale list content on rebuilds on content changes.

This commit also improves the above error message.

Fixes #4845

Diffstat:
Mhugolib/page_output.go | 3+++
Mhugolib/site.go | 2++
2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/hugolib/page_output.go b/hugolib/page_output.go
@@ -141,6 +141,9 @@ func (p *PageOutput) Render(layout ...string) template.HTML {
 }
 
 func (p *Page) Render(layout ...string) template.HTML {
+	if p.mainPageOutput == nil {
+		panic(fmt.Sprintf("programming error: no mainPageOutput for %q", p.Path()))
+	}
 	return p.mainPageOutput.Render(layout...)
 }
 
diff --git a/hugolib/site.go b/hugolib/site.go
@@ -1492,6 +1492,8 @@ func (s *Site) resetBuildState() {
 
 	s.expiredCount = 0
 
+	spc = newPageCache()
+
 	for _, p := range s.rawAllPages {
 		p.subSections = Pages{}
 		p.parent = nil