Skip to content

Commit

Permalink
Merge pull request #273 from rzajac/mem-file-truncate-use-lock
Browse files Browse the repository at this point in the history
mem.File.Truncate should use lock
  • Loading branch information
0xmichalis authored Nov 15, 2020
2 parents 6c06305 + d175ebc commit 736b98e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mem/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ func (f *File) Truncate(size int64) error {
if size < 0 {
return ErrOutOfRange
}
f.fileData.Lock()
defer f.fileData.Unlock()
if size > int64(len(f.fileData.data)) {
diff := size - int64(len(f.fileData.data))
f.fileData.data = append(f.fileData.data, bytes.Repeat([]byte{00}, int(diff))...)
Expand Down

0 comments on commit 736b98e

Please sign in to comment.