Packet cleanup without locks

Prevents use of invalid mutexes during mosquitto_destroy.

Closes #1914. Thanks to Nikolay Raspopov.
This commit is contained in:
Roger A. Light 2020-11-27 15:30:11 +00:00
parent 7ccf4c44fd
commit a3258f7d82
3 changed files with 11 additions and 5 deletions

View File

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

View File

@ -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;
pthread_mutex_lock(&mosq->current_out_packet_mutex);
pthread_mutex_lock(&mosq->out_packet_mutex);
/* Out packet cleanup */
if(mosq->out_packet && !mosq->current_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);
}
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->current_out_packet_mutex);

View File

@ -22,6 +22,7 @@ Contributors:
int packet__alloc(struct mosquitto__packet *packet);
void packet__cleanup(struct mosquitto__packet *packet);
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__check_oversize(struct mosquitto *mosq, uint32_t remaining_length);