Skip to content

Commit 820586b

Browse files
committed
Fix MQTT client io_desc slot leak on error/disconnect (5738)
1 parent e05c4de commit 820586b

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/port/stm32h563/mqtt_client.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,14 @@ static int handle_disconnecting(void)
462462
ctx.socket_fd = -1;
463463
}
464464

465+
/* Release the wolfMQTT/wolfIP io_desc slot (in_use sentinel) so it is
466+
* not leaked from the fixed MAX_WOLFMQTT_CTX pool. NULL it to avoid a
467+
* double free if this path is re-entered. */
468+
if (ctx.io_ctx) {
469+
wolfMQTT_Cleanup_wolfIP(ctx.io_ctx);
470+
ctx.io_ctx = NULL;
471+
}
472+
465473
ctx.state = MQTT_STATE_IDLE;
466474
}
467475

@@ -513,6 +521,13 @@ int mqtt_client_poll(void)
513521
wolfIP_sock_close(ctx.stack, ctx.socket_fd);
514522
ctx.socket_fd = -1;
515523
}
524+
/* Release the wolfMQTT/wolfIP io_desc slot (in_use sentinel) so it
525+
* is not leaked from the fixed MAX_WOLFMQTT_CTX pool. NULL it to
526+
* avoid a double free if this path is re-entered. */
527+
if (ctx.io_ctx) {
528+
wolfMQTT_Cleanup_wolfIP(ctx.io_ctx);
529+
ctx.io_ctx = NULL;
530+
}
516531
ctx.publish_pending = 0;
517532
ctx.state = MQTT_STATE_IDLE;
518533
break;

0 commit comments

Comments
 (0)