:: commit 7bcc2025de25cf1c480d3637813d20d4839bf9b7

Mintsuki <mintsuki@protonmail.com> — 2026-02-08 17:23

parents: 2fd9d3face

lib/getchar: Fix timer event leak and spurious timeout in ESC handler

diff --git a/common/lib/getchar.c b/common/lib/getchar.c
index 8f568a68..60d17d5d 100644
--- a/common/lib/getchar.c
+++ b/common/lib/getchar.c
@@ -323,6 +323,8 @@ again:
     }
 
     if (kd.Key.ScanCode == SCAN_ESC) {
+        gBS->CloseEvent(events[1]);
+
         gBS->CreateEvent(EVT_TIMER, TPL_CALLBACK, NULL, NULL, &events[1]);
 
         gBS->SetTimer(events[1], TimerRelative, 100000);
@@ -330,6 +332,7 @@ again:
         gBS->WaitForEvent(2, events, &which);
 
         if (which == 1) {
+            gBS->CloseEvent(events[1]);
             return GETCHAR_ESCAPE;
         }
 
@@ -339,11 +342,16 @@ again:
             status = exproto->ReadKeyStrokeEx(exproto, &kd);
         }
 
+        gBS->CloseEvent(events[1]);
+        gBS->CreateEvent(EVT_TIMER, TPL_CALLBACK, NULL, NULL, &events[1]);
+        gBS->SetTimer(events[1], TimerRelative, (uint64_t)10000000 * seconds);
+
         if (status != EFI_SUCCESS) {
             goto again;
         }
 
         if (kd.Key.UnicodeChar == '[') {
+            gBS->CloseEvent(events[1]);
             return input_sequence(!use_sproto, exproto, sproto);
         }
     }
tab: 248 wrap: offon