mirror of
https://github.com/esphome/esphome.git
synced 2026-03-24 06:53:07 +08:00
[api][serial_proxy] Fix dangling pointer (#14640)
This commit is contained in:
@@ -155,6 +155,18 @@ APIConnection::~APIConnection() {
|
||||
voice_assistant::global_voice_assistant->client_subscription(this, false);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
if (zwave_proxy::global_zwave_proxy != nullptr && zwave_proxy::global_zwave_proxy->get_api_connection() == this) {
|
||||
zwave_proxy::global_zwave_proxy->zwave_proxy_request(this, enums::ZWAVE_PROXY_REQUEST_TYPE_UNSUBSCRIBE);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_SERIAL_PROXY
|
||||
for (auto *proxy : App.get_serial_proxies()) {
|
||||
if (proxy->get_api_connection() == this) {
|
||||
proxy->serial_proxy_request(this, enums::SERIAL_PROXY_REQUEST_TYPE_UNSUBSCRIBE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void APIConnection::destroy_active_iterator_() {
|
||||
|
||||
@@ -74,6 +74,9 @@ class SerialProxy : public uart::UARTDevice, public Component {
|
||||
/// @param data_size Number of data bits (5-8)
|
||||
void configure(uint32_t baudrate, bool flow_control, uint8_t parity, uint8_t stop_bits, uint8_t data_size);
|
||||
|
||||
/// Get the currently subscribed API connection (nullptr if none)
|
||||
api::APIConnection *get_api_connection() { return this->api_connection_; }
|
||||
|
||||
/// Handle a subscribe/unsubscribe request from an API client
|
||||
void serial_proxy_request(api::APIConnection *api_connection, api::enums::SerialProxyRequestType type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user