From 2bd43d95ced69eec3a7bed86f3d1de27b1dfbb39 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 13 Feb 2026 08:31:20 +0000 Subject: [PATCH] Fix mosquitto_loop_start() leaving the mosq stuct in an invalid state This occurs if thread creation fails. Closes #3496. Thanks to ehoffman2. --- ChangeLog.txt | 6 +++++- lib/thread_mosq.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 4cbce699..81810172 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,4 @@ -2.0.23 - 2026-01-14 +2.0.23 - 2026-xx-xx =================== Broker: @@ -14,6 +14,10 @@ Broker: mosquitto 1.5 or earlier is loaded. Closes #3439. - Limit auto_id_prefix to 50 characters. Closes #3440. +Library: +- Fix mosquitto_loop_start() leaving the mosq stuct in an invalid state if + thread creation fails. Closes #3496. + Windows: - Installer will not overwrite an existing mosquitto.conf diff --git a/lib/thread_mosq.c b/lib/thread_mosq.c index cd3a614a..fd593a36 100644 --- a/lib/thread_mosq.c +++ b/lib/thread_mosq.c @@ -41,7 +41,6 @@ int mosquitto_loop_start(struct mosquitto *mosq) #if defined(WITH_THREADING) if(!mosq || mosq->threaded != mosq_ts_none) return MOSQ_ERR_INVAL; - mosq->threaded = mosq_ts_self; if(!COMPAT_pthread_create(&mosq->thread_id, NULL, mosquitto__thread_main, mosq)){ #if defined(__linux__) pthread_setname_np(mosq->thread_id, "mosquitto loop"); @@ -50,6 +49,7 @@ int mosquitto_loop_start(struct mosquitto *mosq) #elif defined(__FreeBSD__) || defined(__OpenBSD__) pthread_set_name_np(mosq->thread_id, "mosquitto loop"); #endif + mosq->threaded = mosq_ts_self; return MOSQ_ERR_SUCCESS; }else{ return MOSQ_ERR_ERRNO;