VirtualBox

Changeset 103281 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Feb 8, 2024 2:37:11 PM (12 months ago)
Author:
vboxsync
Message:

Dev/PC/DevPit-i8254: Don't leak fd if speaker emulation isn't possible (found by Parfait, improved fix). bugref:3409

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevPit-i8254.cpp

    r103241 r103281  
    13911391        /** @todo r=klaus move this to a (system-specific) driver */
    13921392#ifdef RT_OS_LINUX
     1393        /** @todo r=andy Use #defines / enums(?) for all those uPassthroughSpeaker below. */
    13931394        int fd = -1;
    1394         if ((uPassthroughSpeaker == 1 || uPassthroughSpeaker == 100) && fd == -1)
     1395        if (uPassthroughSpeaker == 1 || uPassthroughSpeaker == 100)
    13951396            fd = pitR3TryDeviceOpenSanitizeIoctl("/dev/input/by-path/platform-pcspkr-event-spkr", O_WRONLY);
    1396         if ((uPassthroughSpeaker == 2 || uPassthroughSpeaker == 100) && fd == -1)
     1397
     1398        if (fd == -1 && (uPassthroughSpeaker == 2 || uPassthroughSpeaker == 100))
    13971399            fd = pitR3TryDeviceOpenSanitizeIoctl("/dev/tty", O_WRONLY);
    1398         if ((uPassthroughSpeaker == 3 || uPassthroughSpeaker == 100) && fd == -1)
     1400
     1401        if (fd == -1 && (uPassthroughSpeaker == 3 || uPassthroughSpeaker == 100))
    13991402        {
    14001403            fd = pitR3TryDeviceOpenSanitizeIoctl("/dev/tty0", O_WRONLY);
     
    14021405                fd = pitR3TryDeviceOpenSanitizeIoctl("/dev/vc/0", O_WRONLY);
    14031406        }
    1404         if ((uPassthroughSpeaker == 9 || uPassthroughSpeaker == 100) && pszPassthroughSpeakerDevice && fd == -1)
     1407
     1408        if (fd == -1 && (uPassthroughSpeaker == 9 || uPassthroughSpeaker == 100) && pszPassthroughSpeakerDevice)
    14051409            fd = pitR3TryDeviceOpenSanitizeIoctl(pszPassthroughSpeakerDevice, O_WRONLY);
    1406         if (pThisCC->enmSpeakerEmu == PIT_SPEAKER_EMU_NONE && fd != -1)
     1410
     1411        if (fd != -1)
    14071412        {
    1408             pThisCC->hHostSpeaker = fd;
    14091413            if (ioctl(fd, EVIOCGSND(0)) != -1)
    14101414            {
     
    14171421                LogRel(("PIT: speaker: emulation mode console\n"));
    14181422            }
     1423            pThisCC->hHostSpeaker = fd;
    14191424        }
    1420         if ((uPassthroughSpeaker == 70 || uPassthroughSpeaker == 100) && fd == -1)
    1421             fd = pitR3TryDeviceOpen("/dev/tty", O_WRONLY);
    1422         if ((uPassthroughSpeaker == 79 || uPassthroughSpeaker == 100) && pszPassthroughSpeakerDevice && fd == -1)
    1423             fd = pitR3TryDeviceOpen(pszPassthroughSpeakerDevice, O_WRONLY);
    1424         if (pThisCC->enmSpeakerEmu == PIT_SPEAKER_EMU_NONE && fd != -1)
     1425        else
    14251426        {
    1426             pThisCC->hHostSpeaker = fd;
    1427             pThisCC->enmSpeakerEmu = PIT_SPEAKER_EMU_TTY;
    1428             LogRel(("PIT: speaker: emulation mode tty\n"));
    1429         }
    1430         if (pThisCC->enmSpeakerEmu == PIT_SPEAKER_EMU_NONE)
    1431         {
     1427            if (uPassthroughSpeaker == 70 || uPassthroughSpeaker == 100)
     1428                fd = pitR3TryDeviceOpen("/dev/tty", O_WRONLY);
     1429            if (fd == -1 && (uPassthroughSpeaker == 79 || uPassthroughSpeaker == 100) && pszPassthroughSpeakerDevice)
     1430                fd = pitR3TryDeviceOpen(pszPassthroughSpeakerDevice, O_WRONLY);
    14321431            if (fd != -1)
    14331432            {
    1434                 close(fd);
    1435                 fd = -1;
     1433                pThisCC->enmSpeakerEmu = PIT_SPEAKER_EMU_TTY;
     1434                pThisCC->hHostSpeaker  = fd;
     1435                LogRel(("PIT: speaker: emulation mode tty\n"));
    14361436            }
    1437             LogRel(("PIT: speaker: no emulation possible\n"));
     1437            else
     1438                LogRel(("PIT: speaker: no emulation possible\n"));
    14381439        }
    1439 #else
     1440#else  /* !RT_OS_LINUX */
    14401441        LogRel(("PIT: speaker: emulation deactivated\n"));
    1441 #endif
     1442#endif /* !RT_OS_LINUX */
    14421443        if (pszPassthroughSpeakerDevice)
    14431444        {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette