SubGHz: Add Manually -> Security+ 2.0 leaks a transmitter on every key generation
Found while reviewing #1104, which fixes the same class of problem on the TX path.
What
subghz_txrx_gen_secplus_v2_protocol() allocates a transmitter and never frees it:
instance->transmitter =
subghz_transmitter_alloc_init(instance->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
subghz_txrx_set_preset(instance, name_preset, frequency, NULL, 0);
if(instance->transmitter) {
subghz_protocol_secplus_v2_create_data(...);
ret = true;
}
return ret; // <- no subghz_transmitter_free()Every one of the other 13 subghz_txrx_gen_*_protocol() functions in that file ends with subghz_transmitter_free(...->transmitter). This one does not, so the SubGhzTransmitter plus the encoder instance it owns are leaked.
Reachability
SubGHz -> Add Manually -> Security+ 2.0, i.e. every time a Sec+ 2.0 key is generated. Leaks again on each repeat.
Notes
It also leaves a live orphan pointer in the shared SubGhzTxRx::transmitter field, which the next subghz_txrx_tx_start() silently overwrites at the assignment in subghz_txrx.c. That is the wider problem tracked separately.
Not hardware-tested; found by code inspection during the #1104 review.
@xMasterX could you confirm this reading before I put a fix together? Assigning to you for a sanity check.
Source: DarkFlippers/unleashed-firmware