-
Notifications
You must be signed in to change notification settings - Fork 17
SC: Add destructor to wasm_allocator to release memory #39
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
Conversation
include/eosio/vm/allocator.hpp
Outdated
| page = 0; | ||
| } | ||
| ~wasm_allocator() { | ||
| if (raw) { |
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.
Isn't there a problem if free() is called and something else mmap into the same old raw location. This could free some other mmap. Seems like free() should set raw = nullptr.
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.
I wonder if making free() private would be the way to go here. Seems like that or you need to sprinkle in some EOS_VM_ASSERT(raw, wasm_bad_alloc, "already freed"); and set raw = nullptr inside free().
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.
I am afraid that modifying free() or making it private might break some existing uses (although Spring does not use free directly).
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.
I wonder if making
free()private would be the way to go here
or just rename free() as the dtor? free() isn't used anywhere
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.
Thank both of you. I renamed free to the destructor.
spoonincode
left a comment
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.
whoops didn't mean to dismiss, seems fine
Change Description
wasm_allocatordid not implement destructors, and memory it allocated was not released. It caused memory exhaustion when running unit_test.The PR adds a destructor to free the memory.
I re-run
unit_testwith this change and was able to run to the completion.Resolves AntelopeIO/spring#1407
API Changes
Documentation Additions