Heap accounting ($SYS/broker/heap/current) is incorrect #3192
Labels
Component: libmosquitto
Component: mosquitto-broker
Status: Completed
Nothing further to be done with this issue, it can be closed by the requestor or committer.
Milestone
Mosquitto version: 2.0.11, 2.0.20
Platform: 32-bit ARM running Debian Stable (Bookworm)
Bug: The value reported via
$SYS/broker/heap/current
gradually increases when the broker is receiving MQTT v5 publish with properties, despite the memory usage for mosquitto reported byps
not increasing.Having tracked this down, this is due to the
mosquitto_property_add_*()
family of allocating themosquitto_property
struct usingmosquitto__calloc()
(which adds the usable size of the allocation tomemcount
) butproperty__free()
(called by e.g.mosquitto_property_free_all()
) using a direct call tofree()
, and thus not removing the usable size frommemcount
.Thus, if one makes use of the
memory_limit
configuration option, one eventually runs into the allocator functions incorrectly refusing to allocate memory.Expected behaviour:
$SYS/broker/heap/current
should gradually increase over time when the actual memory usage of the mosquitto process is not increasing.The incorrect call to
free()
was located using a custom-written preloaded shared object to intercept the C library allocation/free calls, track the memory allocations, verify that there are indeed no leaks, but also check how they are called (e.g. from where in the binary, or in the case of the tail-calledfree()
, whether ARM register R2 contains the pointer to memcount) and print this information. This was then followed by analysis of the assembly and C code to validate the results.The text was updated successfully, but these errors were encountered: