Span lock state error when realloc, May overwrite by user's data?
fly3366 opened this issue · comments
Saturn IDC commented
package main
import (
"log"
"sync"
"unsafe"
"github.com/heiyeluren/xmm"
)
func main() {
print("Start\n")
f := xmm.Factory{}
m, err := f.CreateMemory(0.6)
if err != nil {
panic(err)
}
lock := sync.Mutex{}
wg := sync.WaitGroup{}
for i := 0; i < 2; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := 1; i <= 1024; i++ {
lock.Lock()
addr, err := m.Alloc(uintptr(i * 4096))
lock.Unlock()
if err != nil {
log.Fatalf("%s", err)
}
s := (*[1024 * 4096]byte)(addr)[:uintptr(i*4096):uintptr(i*4096)]
for idx := range s {
s[idx] = 255
}
lock.Lock()
err = m.Free(uintptr(unsafe.Pointer(&s[0])))
lock.Unlock()
if err != nil {
panic(err)
}
}
}()
}
wg.Wait()
}
黑夜路人 commented
Can you track and check the call logic in the middle of the source code? If any bugs can be found, they can be fixed and a PR can be submitted later. Thank you