Skip to content

Commit d8812a1

Browse files
committed
fix: prevent keypress memory leak with multiple Inquirerer instances
- TerminalKeypress.pause() now resets raw mode (setRawMode(false)) to prevent raw mode from leaking into subsequent text prompts after checkbox/autocomplete - Inquirerer.close() now nullifies this.rl and this.keypress references so subsequent calls detect the closed state and double-close is safe
1 parent d41fae5 commit d8812a1

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

packages/inquirerer/src/keypress.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ export class TerminalKeypress {
150150
pause(): void {
151151
this.active = false;
152152
this.clearHandlers();
153+
if (typeof (this.input as any).setRawMode === 'function') {
154+
(this.input as any).setRawMode(false);
155+
}
153156
}
154157

155158
resume(): void {

packages/inquirerer/src/prompt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,11 @@ export class Inquirerer {
13291329
public close() {
13301330
if (this.rl) {
13311331
this.rl.close();
1332+
this.rl = null;
1333+
}
1334+
if (this.keypress) {
13321335
this.keypress.destroy();
1336+
this.keypress = null;
13331337
}
13341338
}
13351339
}

0 commit comments

Comments
 (0)