Skip to content

Close vfs: invalid memory address or nil pointer dereference

The problem cannot be reproduced when running go run test.go in PowerShell, but can be reproduced in cmd and wsl. Interestingly, the same problem still occurs when running the executable file with go build.

Code:

package main

import (
	"embed"

	"modernc.org/sqlite/vfs"
)

//go:embed test.go
var FS embed.FS

func main() {
	_, f, err := vfs.New(FS)
	if err != nil {
		panic(err)
	}
	f.Close()
}

Log:

D:\projects\bly\go-test\db>go run test.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x1 addr=0xb0 pc=0x23c7ea]

goroutine 1 [running]:
modernc.org/memory.(*Allocator).UintptrFree(0x2?, 0xc00014de98?)
        C:/Users/yurun/go/pkg/mod/modernc.org/memory@v1.9.1/memory.go:221 +0xea
modernc.org/libc.Xfree(0xc000140180?, 0x2bc7d490028?)
        C:/Users/yurun/go/pkg/mod/modernc.org/libc@v1.61.13/mem.go:97 +0x8d
modernc.org/sqlite/vfs.(*FS).Close(0xc00011e1c0)
        C:/Users/yurun/go/pkg/mod/modernc.org/sqlite@v1.36.2/vfs/patches.go:220 +0xd2
main.main()
        D:/projects/bly/go-test/db/test.go:17 +0x32
exit status 2