Skip to content

Conversation

@linh2931
Copy link
Contributor

@linh2931 linh2931 commented Apr 19, 2025

Change Description

wasm_allocator did 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_test with this change and was able to run to the completion.

Resolves AntelopeIO/spring#1407

API Changes

  • API Changes

Documentation Additions

  • Documentation Additions

@linh2931 linh2931 requested review from heifner and spoonincode April 19, 2025 19:38
spoonincode
spoonincode previously approved these changes Apr 21, 2025
page = 0;
}
~wasm_allocator() {
if (raw) {
Copy link
Contributor

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.

Copy link
Contributor

@heifner heifner Apr 21, 2025

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().

Copy link
Contributor Author

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).

Copy link
Contributor

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

Copy link
Contributor Author

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 spoonincode dismissed their stale review April 21, 2025 21:54

map_failed

Copy link
Contributor

@spoonincode spoonincode left a 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

@linh2931 linh2931 merged commit afc0096 into sync_call Apr 22, 2025
10 checks passed
@linh2931 linh2931 deleted the wasm_alloc_dtor branch April 22, 2025 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants