Skip to content

Commit

Permalink
fix #17: proper embedded alignment of handleCounter
Browse files Browse the repository at this point in the history
amd32 (raspberrypi) requires specific alignment for atomic operations to
work, or else you'll get "panic: runtime error: invalid memory address
or nil pointer dereference". Turns out this alignment is important for
embedded structs as well.
Embedding as the first member in the struct, and putting the atomic
field at the start of the embedded struct makes the alignment correct.
  • Loading branch information
djherbis committed Apr 15, 2020
1 parent 646777d commit 6707f14
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ func (a *accessor) RemoveFile(key string) {
}

type cachedFile struct {
stream *stream.Stream
handleCounter
stream *stream.Stream
}

func (c *FSCache) newFile(name string) (fileStream, error) {
Expand All @@ -236,9 +236,9 @@ func (c *FSCache) oldFile(name string) fileStream {
}

type reloadedFile struct {
handleCounter
fs FileSystem
name string
handleCounter
io.WriteCloser // nop Write & Close methods. will never be called.
}

Expand Down

0 comments on commit 6707f14

Please sign in to comment.