Fix mosquitto_loop_start() leaving the mosq struct 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:33:32 +00:00
parent 7984e50f75
commit da7d02690b
2 changed files with 8 additions and 4 deletions

View file

@ -1,7 +1,7 @@
2.1.3 - 2026-02-xx
==================
# Broker:
# Broker
- Fix MOSQ_EVT_DISCONNECT being called before MOSQ_EVT_ACL_CHECK for the will
of that client. Closes #3487.
@ -9,6 +9,10 @@
- Fix potential crash if reading a file in restricted mode and the group id
does not have an entry in /etc/groups. Closes #3498.
# Lib
- Fix mosquitto_loop_start() leaving the mosq struct in an invalid state if
thread creation fails. Closes #3496.
# Plugins
- Fix migrate_to_persist_sqlite.py not base64 decoding message payloads when
migrating. Closes #3492.
@ -20,11 +24,11 @@
2.1.2 - 2026-02-09
==================
Broker:
# Broker
- Forbid running with `persistence true` and with a persistence plugin at the
same time.
Build:
# Build
- Build fixes for OpenBSD. Closes #3474.
- Add missing libedit to docker builds. Closes #3476.
- Fix static/shared linking of libwebsockets under cmake.

View file

@ -48,7 +48,6 @@ int mosquitto_loop_start(struct mosquitto *mosq)
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");
@ -57,6 +56,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;