fix: initialize mosquittopp base class in initializer list

The MQTT constructor was incorrectly attempting to call the base class
constructor in the constructor body:

  mosquittopp(name.c_str());

This creates a temporary mosquittopp object that is immediately destroyed,
leaving the actual base class uninitialized. When connect() is subsequently
called, it uses methods from the uninitialized base class, causing a segfault.

Move the base class initialization to the member initializer list where it
belongs.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Isaac Connor
2026-02-02 19:38:49 -05:00
parent ea0c79464c
commit cbfa476d06

View File

@@ -9,12 +9,10 @@
#include <string.h>
MQTT::MQTT(Monitor *monitor) :
mosqpp::mosquittopp(("ZoneMinder"+std::to_string(monitor->Id())).c_str()),
monitor_(monitor),
connected_(false)
{
std::string name="ZoneMinder"+std::to_string(monitor->Id());
mosquittopp(name.c_str());
mosqpp::lib_init();
connect();
}