From 99b4836a1e463a225a003623cce09f462d77f4d2 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 4 Oct 2019 16:53:51 +0200 Subject: [PATCH] Fix memory leaks in the outgoing packet queue. Found by AddressSanitizer. --- src/meshlink.c | 8 ++++++++ src/meshlink_queue.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/meshlink.c b/src/meshlink.c index 8ed94626..90d64648 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1604,6 +1604,12 @@ void meshlink_close(meshlink_handle_t *mesh) { close(mesh->netns); } + for(vpn_packet_t *packet; (packet = meshlink_queue_pop(&mesh->outpacketqueue));) { + free(packet); + } + + meshlink_queue_exit(&mesh->outpacketqueue); + free(mesh->name); free(mesh->appname); free(mesh->confbase); @@ -1778,6 +1784,8 @@ void meshlink_send_from_queue(event_loop_t *loop, meshlink_handle_t *mesh) { mesh->self->in_packets++; mesh->self->in_bytes += packet->len; route(mesh, mesh->self, packet); + + free(packet); } ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination) { diff --git a/src/meshlink_queue.h b/src/meshlink_queue.h index 99623180..764f4162 100644 --- a/src/meshlink_queue.h +++ b/src/meshlink_queue.h @@ -45,6 +45,10 @@ static inline void meshlink_queue_init(meshlink_queue_t *queue) { pthread_mutex_init(&queue->mutex, &attr); } +static inline void meshlink_queue_exit(meshlink_queue_t *queue) { + pthread_mutex_destroy(&queue->mutex); +} + static inline bool meshlink_queue_push(meshlink_queue_t *queue, void *data) { meshlink_queue_item_t *item = malloc(sizeof(*item)); -- 2.39.5