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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions contracts/eosiolib/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ namespace eosio {
T unpack_action_data() {
constexpr size_t max_stack_buffer_size = 512;
size_t size = action_data_size();
char* buffer = (char*)( max_stack_buffer_size < size ? malloc(size) : alloca(size) );
const bool heap_allocation = max_stack_buffer_size < size;
char* buffer = (char*)( heap_allocation ? malloc(size) : alloca(size) );
read_action_data( buffer, size );
return unpack<T>( buffer, size );
auto res = unpack<T>( buffer, size );
// Free allocated memory
if ( heap_allocation ) {
free(buffer);
}
return res;
}

using ::require_auth;
Expand Down