From 736e886ea8a44e0743244f909667981478acd02e Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Mon, 23 Jan 2017 19:51:21 +0900 Subject: [PATCH] Fix a big leak with fswait --- kernel/ds/ringbuffer.c | 9 ++++++++- kernel/fs/pipe.c | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/ds/ringbuffer.c b/kernel/ds/ringbuffer.c index 5d8bd48b..24683167 100644 --- a/kernel/ds/ringbuffer.c +++ b/kernel/ds/ringbuffer.c @@ -65,7 +65,9 @@ void ring_buffer_select_wait(ring_buffer_t * ring_buffer, void * process) { ring_buffer->alert_waiters = list_create(); } - list_insert(ring_buffer->alert_waiters, process); + if (!list_find(ring_buffer->alert_waiters, process)) { + list_insert(ring_buffer->alert_waiters, process); + } list_insert(((process_t *)process)->node_waits, ring_buffer); } @@ -149,6 +151,11 @@ void ring_buffer_destroy(ring_buffer_t * ring_buffer) { free(ring_buffer->wait_queue_writers); free(ring_buffer->wait_queue_readers); + + if (ring_buffer->alert_waiters) { + list_free(ring_buffer->alert_waiters); + free(ring_buffer->alert_waiters); + } } void ring_buffer_interrupt(ring_buffer_t * ring_buffer) { diff --git a/kernel/fs/pipe.c b/kernel/fs/pipe.c index 2a478937..1c24f9d9 100644 --- a/kernel/fs/pipe.c +++ b/kernel/fs/pipe.c @@ -240,7 +240,9 @@ static int pipe_wait(fs_node_t * node, void * process) { pipe->alert_waiters = list_create(); } - list_insert(pipe->alert_waiters, process); + if (!list_find(pipe->alert_waiters, process)) { + list_insert(pipe->alert_waiters, process); + } list_insert(((process_t *)process)->node_waits, pipe); return 0;