-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: allocate C memory for MDB_val in readonly Txn #29
Conversation
Use C.malloc to allocate memory for MDB_val in readonly Txn. CGo does not allow using new() for this. Fixes #28.
Change the C.mdb_filehandle_t declaration to use var instead of new() to clarify that we are not retaining a pointer to anything. This is related to #28, but in this case no issue, because we are not assiging a pointer to Go allocated memory to a C value. Functionally this does not change anything. Go decides if values are stack allocated or heap allocated based on if they escape, not based on the syntax.
@@ -943,6 +943,9 @@ func TestTxn_Reset_readonly_C_free(t *testing.T) { | |||
|
|||
// Since this is a readonly transaction, the global Env key/val cannot be | |||
// reused and new C memory must be allocated. | |||
if txn.key == env.ckey || txn.val == env.cval { | |||
t.Error("env.ckey and cval must not be used in a readonly Txn") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Co-authored-by: Shane Kerr <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I've run my code with this patch for a while and didn't see the problem anymore. Thanks! Now I will also remove the goroutine stuff, which would probably have fixed it anyway somehow. |
Use C.malloc to allocate memory for MDB_val in readonly Txn.
CGo does not allow using new() for this. This can lead to an "cgo argument has Go pointer to unpinned Go pointer" CGo error.
Fixes #28.
TODO:
Also fix the FD() usage of new() if needed.Not needed, but changed syntax for clarity.@fiatjaf: does this fix the error you encountered?