Fix defects identified by Coverity.

pull/211/merge
Roger A. Light 11 years ago
parent 5ac576f2ab
commit 3fd1dc477f

@ -80,13 +80,14 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge)
HASH_FIND(hh_id, db->contexts_by_id, local_id, strlen(local_id), new_context); HASH_FIND(hh_id, db->contexts_by_id, local_id, strlen(local_id), new_context);
if(new_context){ if(new_context){
/* (possible from persistent db) */ /* (possible from persistent db) */
_mosquitto_free(local_id);
}else{ }else{
/* id wasn't found, so generate a new context */ /* id wasn't found, so generate a new context */
new_context = mqtt3_context_init(db, -1); new_context = mqtt3_context_init(db, -1);
if(!new_context){ if(!new_context){
return MOSQ_ERR_NOMEM; return MOSQ_ERR_NOMEM;
} }
new_context->id = _mosquitto_strdup(local_id); new_context->id = local_id;
HASH_ADD_KEYPTR(hh_id, db->contexts_by_id, new_context->id, strlen(new_context->id), new_context); HASH_ADD_KEYPTR(hh_id, db->contexts_by_id, new_context->id, strlen(new_context->id), new_context);
} }
new_context->bridge = bridge; new_context->bridge = bridge;

@ -468,6 +468,7 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context)
ws_ctxt_user_head = (struct libws_mqtt_hack *)libwebsocket_context_user(found_context->ws_context); ws_ctxt_user_head = (struct libws_mqtt_hack *)libwebsocket_context_user(found_context->ws_context);
ws_ctxt_user = _mosquitto_calloc(1, sizeof(struct libws_mqtt_hack)); ws_ctxt_user = _mosquitto_calloc(1, sizeof(struct libws_mqtt_hack));
if(!ws_ctxt_user){ if(!ws_ctxt_user){
rc = MOSQ_ERR_NOMEM;
goto handle_connect_error; goto handle_connect_error;
} }
ws_ctxt_user->old_mosq = found_context; ws_ctxt_user->old_mosq = found_context;
@ -492,20 +493,16 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context)
ws_ctxt_user_head = (struct libws_mqtt_hack *)libwebsocket_context_user(found_context->ws_context); ws_ctxt_user_head = (struct libws_mqtt_hack *)libwebsocket_context_user(found_context->ws_context);
ws_ctxt_user = _mosquitto_calloc(1, sizeof(struct libws_mqtt_hack)); ws_ctxt_user = _mosquitto_calloc(1, sizeof(struct libws_mqtt_hack));
if(!ws_ctxt_user){ if(!ws_ctxt_user){
rc = MOSQ_ERR_NOMEM;
goto handle_connect_error; goto handle_connect_error;
} }
ws_ctxt_user->old_mosq = context; ws_ctxt_user->old_mosq = context;
ws_ctxt_user->new_mosq = found_context; ws_ctxt_user->new_mosq = found_context;
if(ws_ctxt_user_head){ while(ws_ctxt_user_head->next){
while(ws_ctxt_user_head->next){ ws_ctxt_user_head = ws_ctxt_user_head->next;
ws_ctxt_user_head = ws_ctxt_user_head->next;
}
ws_ctxt_user_head->next = ws_ctxt_user;
}else{
ws_ctxt_user->next = ws_ctxt_user_head->next;
ws_ctxt_user_head->next = ws_ctxt_user;
} }
ws_ctxt_user_head->next = ws_ctxt_user;
HASH_ADD_KEYPTR(hh_for_free, db->contexts_for_free, context, sizeof(void *), context); HASH_ADD_KEYPTR(hh_for_free, db->contexts_for_free, context, sizeof(void *), context);
}else{ }else{
HASH_ADD_KEYPTR(hh_for_free, db->contexts_for_free, context, sizeof(void *), context); HASH_ADD_KEYPTR(hh_for_free, db->contexts_for_free, context, sizeof(void *), context);

@ -141,10 +141,15 @@ static int callback_mqtt(struct libwebsocket_context *context,
mosq->ws_context = context; mosq->ws_context = context;
mosq->wsi = wsi; mosq->wsi = wsi;
u->mosq = mosq; u->mosq = mosq;
}else{
return -1;
} }
break; break;
case LWS_CALLBACK_CLOSED: case LWS_CALLBACK_CLOSED:
if(!u){
return -1;
}
mosq = u->mosq; mosq = u->mosq;
if(mosq){ if(mosq){
mosq->wsi = NULL; mosq->wsi = NULL;
@ -153,6 +158,9 @@ static int callback_mqtt(struct libwebsocket_context *context,
break; break;
case LWS_CALLBACK_SERVER_WRITEABLE: case LWS_CALLBACK_SERVER_WRITEABLE:
if(!u){
return -1;
}
mosq = u->mosq; mosq = u->mosq;
if(!mosq || mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting){ if(!mosq || mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting){
return -1; return -1;
@ -209,6 +217,9 @@ static int callback_mqtt(struct libwebsocket_context *context,
break; break;
case LWS_CALLBACK_RECEIVE: case LWS_CALLBACK_RECEIVE:
if(!u){
return -1;
}
mosq = u->mosq; mosq = u->mosq;
pos = 0; pos = 0;
buf = (uint8_t *)in; buf = (uint8_t *)in;

Loading…
Cancel
Save