Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Free allocated memory in unpack_action_data #4960

Merged
merged 2 commits into from
Aug 13, 2018
Merged

Conversation

andriantolie
Copy link
Contributor

@andriantolie andriantolie commented Aug 1, 2018

Looking at issue #4930 in these past days, I notice some people are still using unpack_action_data instead of EOSIO_ABI.

When using unpack_action_data and their action structure contains string, it will throw "env.free unresolveable" when uploading the contract. I guess it's not linked with the free defined in eosiolib.cpp?

@@ -50,7 +50,11 @@ namespace eosio {
size_t size = action_data_size();
char* buffer = (char*)( max_stack_buffer_size < size ? malloc(size) : alloca(size) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add:
const bool heap_allocation = max_stack_buffer_size < size;
and use heap_allocation in both places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. It makes it clearer to read :)
I've updated the PR

@heifner
Copy link
Contributor

heifner commented Aug 2, 2018

@andriantolie I fail to see how this would have anything to do with "env.free unresolveable". Where you able to reproduce the "env.free unresolveable" error? And if so, did this fix it?

@andriantolie
Copy link
Contributor Author

Yes, this actually doesn't really solve "env.free unresolvable" entirely. But this just solves the "env.free unresolvable" problem when people creates a simple contract with just unpack_action_data.

I couldn't figure out the reasoning behind this. But seems people get "env.free unresolvable" error when they include string object inside his action struct, but never called "free" function anywhere in the contract. That's why when people use EOSIO_ABI, or when they call "free" function at least once in the contract, they don't get the error. In the .wast file, the "free" function turns from "import" to "export" when it is being used in the contract. I don't have sufficient knowledge to understand the reasoning behind this though, so if somebody can explain I'm really happy to learn....

@heifner
Copy link
Contributor

heifner commented Aug 3, 2018

@larryk85 @spoonincode Is there someway we can tell wast to export instead of import to solve this unresolvable error without having to actually call free? The memory will all be free'd at the end of the action, so seems like a waste to free when it is not necessary.

@wanderingbort wanderingbort merged commit 2935e57 into develop Aug 13, 2018
@wanderingbort wanderingbort deleted the free-malloc branch August 13, 2018 21:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants