-
Notifications
You must be signed in to change notification settings - Fork 46
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
Store copy of default buffer to shared user buffer #320
Conversation
Thank you for the hard work on this!
|
src/lmdb-js.h
Outdated
typedef struct user_buffer_t { | ||
MDB_val buffer; | ||
napi_env env; |
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.
This isn't actually used (read) is it? (And I thought it was considered unsafe to store napi_env anyway)
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.
It's referenced in the destructor so that the ref can be released: https://github.com/kriszyp/lmdb-js/pull/320/files#diff-f38d85b2982fc3a98c8a1dfe5f1cab0eea8b2e9ad9657f69d3e6338f9a25079dR1079.
Hmm, yeah storing the napi_env
is probably a bad idea. Might be moot if since I will probably store the value instead of the napi_ref
.
Fixes a memory bug where underlying buffer data was no longer available causing the V8 garbage collected to crash Node.js.
The culprit was due to at least three things:
getUserSharedBuffer()
returnedThe solution is to create a copy of the default buffer data and store it in the
user_buffer_t
. When the shared user buffer is requested, the smart pointer's reference count is incremented, and a new V8 ArrayBuffer value is returned.Since the bug has been fixed, the changes to
read.js
from 3a18645 have been reverted.