drivers/pty: Destroy TTYs when usage is complete.

Otherwise, they will be "reused" and persist settings
and buffers, which we don't want.

Fixes the remaining part of #18488.
This commit is contained in:
Augustin Cavalier
2023-07-11 11:33:00 -04:00
parent 4b02e067a6
commit ed3d3b1023
+18 -1
View File
@@ -212,7 +212,7 @@ master_open(const char *name, uint32 flags, void **_cookie)
if (findUnusedTTY) {
for (index = 0; index < (int32)kNumTTYs; index++) {
if (gMasterTTYs[index] == NULL || gMasterTTYs[index]->ref_count == 0)
if (gMasterTTYs[index] == NULL)
break;
}
if (index >= (int32)kNumTTYs)
@@ -346,9 +346,26 @@ pty_free_cookie(void *_cookie)
{
// The TTY is already closed. We only have to free the cookie.
tty_cookie *cookie = (tty_cookie *)_cookie;
struct tty *tty = cookie->tty;
MutexLocker globalLocker(gGlobalTTYLock);
gTTYModule->tty_destroy_cookie(cookie);
if (tty->ref_count == 0) {
// We need to destroy both master and slave TTYs at the same time,
// and in the proper order.
int32 index = get_tty_index(tty);
if (index < 0)
return B_OK;
if (gMasterTTYs[index]->ref_count == 0 && gSlaveTTYs[index]->ref_count == 0) {
gTTYModule->tty_destroy(gSlaveTTYs[index]);
gTTYModule->tty_destroy(gMasterTTYs[index]);
gMasterTTYs[index] = gSlaveTTYs[index] = NULL;
}
}
return B_OK;
}