Fix mosquitto_loop_start() leaving the mosq stuct in an invalid state

This occurs if thread creation fails.

Closes #3496. Thanks to ehoffman2.
This commit is contained in:
Roger A. Light
2026-02-13 08:31:20 +00:00
parent d757a5097a
commit 2bd43d95ce
2 changed files with 6 additions and 2 deletions

View File

@@ -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

View File

@@ -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;