wallet-core
wallet-core copied to clipboard
Improves memory handling in TWAnyAddress
Describe the bug
Not really a bug: create a class to automatically handle deallocation of TWAnyAddress object.
Additional context https://github.com/trustwallet/wallet-core/blob/master/src/interface/TWAnyAddress.cpp#L16
struct TWAnyAddress {
TWString* address;
enum TWCoinType coin;
};
void TWAnyAddressDelete(struct TWAnyAddress* _Nonnull address) {
TWStringDelete(address->address);
delete address;
}
I think I misunderstood the real issue here. Here's how I think it should be:
- There is a
TWAnyAddressstruct holding an address (incl. coin) ☑️ - Internals of
TWAnyAddressshould be hidden, should not be visible in the .h file ❗️ -
TWAnyAddresscan can be created from address string or pubkey ☑️ - Methods to obtain address string / coin from
TWAnyAddress(TWAnyAddressDescription,TWAnyAddressCoin) ☑️ -
TWAnyAddressDeleteto clean up address object when no longer needed ☑️ - Since internals is not visible to outside,
std::stringcan be used to store the string inside the struct. ❗️
So the proposed changes:
- Move definition of internals of
TWAnyAddressto the .cpp file - Change the type of
addressfield fromTWString*tostd::string