add a refcount to library init/cleanup #1691
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add a refcount around mosquitto_lib_init and mosquitto_lib_cleanup so that multiple calls to init/cleanup don't trigger memory leaks or double-frees.
Another for this change is the following scenario that I have:
The only current solution is that the library requires the application to call mosquitto init/cleanup prior to initializing the library. However, it would be nice if instead both application and library could call init/cleanup and things would "just work" no matter what, especially as many applications won't use mosquitto and shouldn't have to bother about this implementation detail. Further, this breaks my library's abstraction in that if my library ever implements MQTT not using mosquitto (e.g. paho), the applications will be initializing mosquitto for no reason. In other words, this implementation detail (my library using mosquitto internally) should not be leaked to the user.
make test
with your changes locally?"make test" is failing on my machine, but it fails identically on the fixes branch (on
./02-subscribe-qos1.py
).