diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 44c61f86..cbefe374 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -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){ diff --git a/lib/packet_mosq.c b/lib/packet_mosq.c index f291c89d..e32fea35 100644 --- a/lib/packet_mosq.c +++ b/lib/packet_mosq.c @@ -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); diff --git a/lib/packet_mosq.h b/lib/packet_mosq.h index d972d607..b5b10b1e 100644 --- a/lib/packet_mosq.h +++ b/lib/packet_mosq.h @@ -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);