]> git.meshlink.io Git - meshlink/commitdiff
Fix memory leaks in the outgoing packet queue.
authorGuus Sliepen <guus@meshlink.io>
Fri, 4 Oct 2019 14:53:51 +0000 (16:53 +0200)
committerGuus Sliepen <guus@meshlink.io>
Fri, 4 Oct 2019 14:53:51 +0000 (16:53 +0200)
Found by AddressSanitizer.

src/meshlink.c
src/meshlink_queue.h

index 8ed946268b44aa58e3c79345ecd2e4547e8e273a..90d64648ae8945384ac110e1ac3a716ab2a27c72 100644 (file)
@@ -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) {
index 996231807096dc878036492450b24b38c5ecf7ac..764f4162c4b62728752ca042ea3e5a1808adfb14 100644 (file)
@@ -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));