Skip to content

Commit

Permalink
Fix to memory leak on failed MQTT connections. (#105)
Browse files Browse the repository at this point in the history
* Fix to memory memory leak on failed MQTT connections.
* Change MQTT topic name max length from 32 to 48 characters.
* Update CONF:FANx:SOURCE documentation.
  • Loading branch information
tjko authored Aug 12, 2024
1 parent f4344b2 commit 1da4b58
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ Configure source for the PWM signal of a fan.
Source types:
* MBFAN (set fan to follow duty cycle from motherboard fan port)
* SENSOR (set fan to follow temperature based duty cycle)
* VSENSOR (set fan to follow temperature based duty cycle)
* FAN (set fan to follow another FAN output duty cycle)
* FIXED (set fan to run on fixed duty cycle)

Expand Down
2 changes: 1 addition & 1 deletion src/fanpico.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#define WIFI_PASSWD_MAX_LEN 64
#define WIFI_COUNTRY_MAX_LEN 3

#define MQTT_MAX_TOPIC_LEN 33
#define MQTT_MAX_TOPIC_LEN 49
#define MQTT_MAX_USERNAME_LEN 81
#define MQTT_MAX_PASSWORD_LEN 65
#define DEFAULT_MQTT_STATUS_INTERVAL 600
Expand Down
2 changes: 1 addition & 1 deletion src/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void pico_set_system_time(long int sec);
#define DHCP_DEBUG LWIP_DBG_OFF
#define SNTP_DEBUG LWIP_DBG_OFF
#define HTTPD_DEBUG LWIP_DBG_OFF
#define MQTT_DEBUG LWIP_DBG_OFF
#define MQTT_DEBUG LWIP_DBG_ON
#define ALTCP_MBEDTLS_DEBUG LWIP_DBG_ON
#define ALTCP_MBEDTLS_MEM_DEBUG LWIP_DBG_ON
#define ALTCP_MBEDTLS_LIB_DEBUG LWIP_DBG_ON
Expand Down
16 changes: 11 additions & 5 deletions src/mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ static void mqtt_dns_resolve_cb(const char *name, const ip_addr_t *ipaddr, void

void mqtt_connect(mqtt_client_t *client)
{
#if TLS_SUPPORT
static struct altcp_tls_config *tlsconfig = NULL;
#endif
struct mqtt_connect_client_info_t ci;
char client_id[32];
uint16_t port = MQTT_PORT;
Expand Down Expand Up @@ -304,11 +307,14 @@ void mqtt_connect(mqtt_client_t *client)
ci.will_qos = 0;
#if TLS_SUPPORT
if (cfg->mqtt_tls) {
cyw43_arch_lwip_begin();
ci.tls_config = altcp_tls_create_config_client(NULL, 0);
cyw43_arch_lwip_end();
if (!ci.tls_config)
log_msg(LOG_WARNING, "altcp_tls_create_config_client(): failed");
if (!tlsconfig) {
cyw43_arch_lwip_begin();
tlsconfig = altcp_tls_create_config_client(NULL, 0);
cyw43_arch_lwip_end();
if (!tlsconfig)
log_msg(LOG_WARNING, "altcp_tls_create_config_client(): failed");
}
ci.tls_config = tlsconfig;
port = MQTT_TLS_PORT;
}
#endif
Expand Down

0 comments on commit 1da4b58

Please sign in to comment.