NordSecurity / uniffi-bindgen-go

Uniffi bindings generator for Golang
Mozilla Public License 2.0
65 stars 18 forks source link

concurrentHandleMap.tryGet is not safe #28

Closed kegsay closed 7 months ago

kegsay commented 8 months ago

https://github.com/NordSecurity/uniffi-bindgen-go/blob/62347acdf3c00efc54398ef6f0fc3f93e9578df4/bindgen/templates/CallbackInterfaceRuntime.go#L46-L48

Can cause fatal error: concurrent map read and map write as the read is not protected with a mutex.

I'd suggest replacing lock sync.Mutex with a sync.RWMutex.

arg0d commented 8 months ago

I think concurrentHandleMap can be replaced entirely by using cgo.Handle instead.

arg0d commented 8 months ago

Thanks for the report, good catch :+1: