calling RegisterAuthorizer multiple times leaks memory
When RegisterAuthorizer is called multiple times, handleVal keeps callbacks in a map until Close() is called. deleteHandles() should be called every time RegisterAuthorizer is called.
func (c *SQLiteConn) RegisterAuthorizer(callback func(int, string, string, string) int) {
deleteHandles(c) // delete previous callback from handleVal
if callback == nil {
C.sqlite3_set_authorizer(c.db, nil, nil)
} else {
C.sqlite3_set_authorizer(c.db, (*[0]byte)(C.authorizerTrampoline), newHandle(c, callback))
}
}
Yes, when you add/remove many times any callback (authorizer, update hook , rollback hook etc.) library will leak memory. But using deleteHandles don't solve problem, because it deletes all handles, not onlyone of them.
I think that you can do bypass using separate connection each time you want to use authorizer. After closing connection all allocations are cleared, so there will be no leaks.
@graf0 Thank you for the comment. My app works with the above patch by chance because my app only uses authorizer callback. I didn't notice it's working by accident.