Packet cleanup without locks

Prevents use of invalid mutexes during mosquitto_destroy.

Closes #1914. Thanks to Nikolay Raspopov.
pull/1919/head
Roger A. Light 5 years ago
parent 7ccf4c44fd
commit a3258f7d82

@ -294,7 +294,7 @@ void mosquitto__destroy(struct mosquitto *mosq)
mosquitto_property_free_all(&mosq->connect_properties); mosquitto_property_free_all(&mosq->connect_properties);
packet__cleanup_all(mosq); packet__cleanup_all_no_locks(mosq);
packet__cleanup(&mosq->in_packet); packet__cleanup(&mosq->in_packet);
if(mosq->sockpairR != INVALID_SOCKET){ if(mosq->sockpairR != INVALID_SOCKET){

@ -100,13 +100,10 @@ void packet__cleanup(struct mosquitto__packet *packet)
} }
void packet__cleanup_all(struct mosquitto *mosq) void packet__cleanup_all_no_locks(struct mosquitto *mosq)
{ {
struct mosquitto__packet *packet; struct mosquitto__packet *packet;
pthread_mutex_lock(&mosq->current_out_packet_mutex);
pthread_mutex_lock(&mosq->out_packet_mutex);
/* Out packet cleanup */ /* Out packet cleanup */
if(mosq->out_packet && !mosq->current_out_packet){ if(mosq->out_packet && !mosq->current_out_packet){
mosq->current_out_packet = mosq->out_packet; mosq->current_out_packet = mosq->out_packet;
@ -125,6 +122,14 @@ void packet__cleanup_all(struct mosquitto *mosq)
} }
packet__cleanup(&mosq->in_packet); packet__cleanup(&mosq->in_packet);
}
void packet__cleanup_all(struct mosquitto *mosq)
{
pthread_mutex_lock(&mosq->current_out_packet_mutex);
pthread_mutex_lock(&mosq->out_packet_mutex);
packet__cleanup_all_no_locks(mosq);
pthread_mutex_unlock(&mosq->out_packet_mutex); pthread_mutex_unlock(&mosq->out_packet_mutex);
pthread_mutex_unlock(&mosq->current_out_packet_mutex); pthread_mutex_unlock(&mosq->current_out_packet_mutex);

@ -22,6 +22,7 @@ Contributors:
int packet__alloc(struct mosquitto__packet *packet); int packet__alloc(struct mosquitto__packet *packet);
void packet__cleanup(struct mosquitto__packet *packet); void packet__cleanup(struct mosquitto__packet *packet);
void packet__cleanup_all(struct mosquitto *mosq); void packet__cleanup_all(struct mosquitto *mosq);
void packet__cleanup_all_no_locks(struct mosquitto *mosq);
int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet); int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet);
int packet__check_oversize(struct mosquitto *mosq, uint32_t remaining_length); int packet__check_oversize(struct mosquitto *mosq, uint32_t remaining_length);

Loading…
Cancel
Save