From 34a271682700e645c5f524709bb0ae56b2e3e654 Mon Sep 17 00:00:00 2001 From: Gl0w1amp Date: Sat, 29 Nov 2025 05:32:56 +0000 Subject: [PATCH] Add delay in uart_handle_read() to prevent tight polling loop and memory leaks Added Sleep(1) to uart_handle_read when no data is available to simulate hardware I/O latency. This prevents the hook from entering a tight polling loop, which was causing high CPU usage and massive memory leaks. --- hooklib/uart.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hooklib/uart.c b/hooklib/uart.c index 93380c1..7c6ecaf 100644 --- a/hooklib/uart.c +++ b/hooklib/uart.c @@ -200,6 +200,9 @@ static HRESULT uart_handle_read(struct uart *uart, struct irp *irp) int requested = irp->read.nbytes; if (uart->readable.pos < requested && uart->readable.pos == 0) { + /* Avoid a tight polling loop which causes performance issues + and massive memory leaks. Simulate hardware I/O latency. */ + Sleep(1); return E_PENDING; }