Skip to content

Commit

Permalink
fix: handle leak during close in mmap (#1)
Browse files Browse the repository at this point in the history
* fix: handle leak during close in mmap

* add test workflow
  • Loading branch information
ayoubfaouzi authored Jun 27, 2024
1 parent b41f5b2 commit bfaa060
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: build-test

on: [push]

jobs:
test:
name: build-test
strategy:
fail-fast: false
matrix:
go-version: [1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Build
run: |
go env -w GOFLAGS=-mod=mod
go build -v ./...
- name: Test With Coverage
run: go test -race -coverprofile=coverage -covermode=atomic

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: ./coverage
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.21.x'

- name: Go vet
run: |
go vet .
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.21.x'

- name: Go Static Check
run: |
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck .
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.21.x'
5 changes: 5 additions & 0 deletions filestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type FileStream struct {
info os.FileInfo
f *os.File
bs *ByteStream
data mmap.MMap
}

// Assert interface implementation checks
Expand Down Expand Up @@ -48,6 +49,7 @@ func NewFileStream(filename string) (*FileStream, error) {
info: info,
f: f,
bs: bs,
data: data,
}, nil
}

Expand Down Expand Up @@ -111,5 +113,8 @@ func (fs *FileStream) IsEOF() bool {

// Close underlying filestream.
func (fs *FileStream) Close() error {
if fs.data != nil {
_ = fs.data.Unmap()
}
return fs.f.Close()
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/saferwall/binstream
go 1.15

require (
github.com/edsrzf/mmap-go v1.0.0
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d // indirect
github.com/edsrzf/mmap-go v1.1.0
golang.org/x/sys v0.21.0 // indirect
)
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d h1:jbzgAvDZn8aEnytae+4ou0J0GwFZoHR0hOrTg4qH8GA=
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ=
github.com/edsrzf/mmap-go v1.1.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 comments on commit bfaa060

Please sign in to comment.