Return value of mosquitto_new is not checked in mosquittopp::mosquittopp() #113

ralight opened this Issue Mar 15, 2016 · 1 comment


None yet

2 participants

ralight commented Mar 15, 2016

migrated from Bugzilla #473105
status UNCONFIRMED severity normal in component Mosquitto client library for 1.4
Reported in version 1.3.x on platform All
Assigned to: Roger Light

On 2015-07-20 14:24:18 -0400, Trygve Laugstøl wrote:

The v1.3 and v1.4 constructor both look like this:

m_mosq = mosquitto_new(id, clean_session, this);
mosquitto_connect_callback_set(m_mosq, on_connect_wrapper);

If the user does something dumb (like passing in NULL and false for id and clean_session) mosquitto_new will return NULL and set errno to EINVAL. The next call will then execute pthread_mutex_lock(&mosq->callback_mutex); but mosq will be NULL.

I'm not sure what the best way to handle the problem is. Options include throwing an exception, just drop setting the callbacks and have the sub-class/user check errno or have a static method that returns the instance. The last option makes it harder to follow the current pattern of extending mosquittopp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment