Skip to content

fix: mqttsn session fixes, better logging - #19

Open
ChitlangeSahas wants to merge 7 commits into
masterfrom
fix/mqtt-sn-session
Open

fix: mqttsn session fixes, better logging#19
ChitlangeSahas wants to merge 7 commits into
masterfrom
fix/mqtt-sn-session

Conversation

@ChitlangeSahas

Copy link
Copy Markdown
Member

No description provided.

/**
* @brief Function to disconnect from the MQTT-SN gateway.
*/
int mqttsn_disconnect() {

@SeanAkin SeanAkin Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reading through this and I actually think there's a risk socket exhaustion here since you never clean up the tp socket in this method.

@@ -71,23 +71,33 @@ int mqttsn_initialize() {
client_initialized = true;

char *ip_str = getIpAddressFromHostname(CONFIG_FINDMYCAT_CLOUD_HOSTNAME);

@SeanAkin SeanAkin Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no null check on this, what happens if this fails to resolve and gets a NULL value and you pass null into zsock_inet_pton()?

From what I can see it goes into Zephyr's zsock_inet_pton() method which calls z_impl_net_addr_pton this then tries to dereference *src which would be null causing a fatal crash?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this actually, this could cause a full on crash with no recovery?

LOG_HEXDUMP_DBG(&gateway, sizeof(gateway), "gateway");

LOG_INF("Connecting to MQTT-SN server");
LOG_INF("Connecting to MQTT-SN gateway %s:%d as client %s, topic %s", ip_str,

@SeanAkin SeanAkin Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is the last use of ip_str and getIpAddressFromHostname does a memory allocation. You'll want to free up that allocation otherwise it would get lost in memory and I think this would accumulate over time as MQTT-SN is used causing a memory leak due to lost allocations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants