mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-11 05:55:41 +00:00
HASS set pointer to NULL after free, also add cosnt correct
This commit is contained in:
@ -355,7 +355,11 @@ HassDeviceInfo* hass_init_sensor_device_info(ENTITY_TYPE type, int channel) {
|
||||
/// @brief Returns the discovery JSON.
|
||||
/// @param info
|
||||
/// @return
|
||||
char* hass_build_discovery_json(HassDeviceInfo* info) {
|
||||
const char* hass_build_discovery_json(HassDeviceInfo* info) {
|
||||
if (info == NULL) {
|
||||
addLogAdv(LOG_ERROR, LOG_FEATURE_HASS, "ERROR: someone passed NULL pointer to hass_build_discovery_json\r\n");
|
||||
return "";
|
||||
}
|
||||
cJSON_PrintPreallocated(info->root, info->json, HASS_JSON_SIZE, 0);
|
||||
return info->json;
|
||||
}
|
||||
|
||||
@ -60,5 +60,5 @@ HassDeviceInfo* hass_init_light_device_info(ENTITY_TYPE type);
|
||||
HassDeviceInfo* hass_init_power_sensor_device_info(int index);
|
||||
HassDeviceInfo* hass_init_binary_sensor_device_info(int index);
|
||||
HassDeviceInfo* hass_init_sensor_device_info(ENTITY_TYPE type, int channel);
|
||||
char* hass_build_discovery_json(HassDeviceInfo* info);
|
||||
const char* hass_build_discovery_json(HassDeviceInfo* info);
|
||||
void hass_free_device_info(HassDeviceInfo* info);
|
||||
|
||||
@ -1608,6 +1608,7 @@ void doHomeAssistantDiscovery(const char *topic, http_request_t *request) {
|
||||
dev_info = hass_init_relay_device_info(i);
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
hass_free_device_info(dev_info);
|
||||
dev_info = NULL;
|
||||
discoveryQueued = true;
|
||||
}
|
||||
}
|
||||
@ -1619,6 +1620,7 @@ void doHomeAssistantDiscovery(const char *topic, http_request_t *request) {
|
||||
dev_info = hass_init_binary_sensor_device_info(i);
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
hass_free_device_info(dev_info);
|
||||
dev_info = NULL;
|
||||
discoveryQueued = true;
|
||||
}
|
||||
}
|
||||
@ -1631,6 +1633,7 @@ void doHomeAssistantDiscovery(const char *topic, http_request_t *request) {
|
||||
// Enable + RGB control + CW control
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
hass_free_device_info(dev_info);
|
||||
dev_info = NULL;
|
||||
discoveryQueued = true;
|
||||
}
|
||||
else if (pwmCount > 0) {
|
||||
@ -1652,6 +1655,7 @@ void doHomeAssistantDiscovery(const char *topic, http_request_t *request) {
|
||||
if (dev_info != NULL) {
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
hass_free_device_info(dev_info);
|
||||
dev_info = NULL;
|
||||
discoveryQueued = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user