VirtualBox

Ignore:
Timestamp:
Oct 2, 2013 3:27:22 PM (11 years ago)
Author:
vboxsync
Message:

OS X host: leds sync: hopefully fixed all IOKit related memory leaks, also RTMemAlloc/Free() -> malloc/free(). Enabled for testing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.cpp

    r48816 r48823  
    2222*******************************************************************************/
    2323#define LOG_GROUP LOG_GROUP_GUI
    24 //#define VBOX_WITH_KBD_LEDS_SYNC
     24#define VBOX_WITH_KBD_LEDS_SYNC
    2525
    2626#include "DarwinKeyboard.h"
     
    12701270                rc = kIOReturnError;
    12711271        }
     1272
     1273        CFRelease(valueRef);
    12721274    }
    12731275
     
    13131315                rc2 = kIOReturnError;
    13141316            }
    1315 
    1316         }
     1317        }
     1318
     1319        CFRelease(matchingElementsArrayRef);
    13171320    }
    13181321
     
    13591362            }
    13601363        }
     1364
     1365        CFRelease(matchingElementsArrayRef);
    13611366    }
    13621367
     
    13721377    IOHIDElementRef pElementRef = IOHIDValueGetElement(valueRef);
    13731378
    1374     if (IOHIDElementGetUsagePage(pElementRef) == kHIDPage_KeyboardOrKeypad)        /* Keyboard or keypad event */
    1375         if (IOHIDValueGetIntegerValue(valueRef) == 1)                              /* key has been pressed down */
    1376             if (IOHIDElementGetUsage(pElementRef) == kHIDUsage_KeyboardCapsLock || /* CapsLock key has been pressed */
    1377                 IOHIDElementGetUsage(pElementRef) == kHIDUsage_KeypadNumLock)      /* ... or NumLock key has been pressed */
    1378             {
    1379                 Log2(("A modifier key has been pressed\n"));
    1380                 g_LastTouchedState = (VBoxHidLeds_t *)pData;
    1381             }
     1379    if (pElementRef)
     1380    {
     1381        if (IOHIDElementGetUsagePage(pElementRef) == kHIDPage_KeyboardOrKeypad)        /* Keyboard or keypad event */
     1382            if (IOHIDValueGetIntegerValue(valueRef) == 1)                              /* key has been pressed down */
     1383                if (IOHIDElementGetUsage(pElementRef) == kHIDUsage_KeyboardCapsLock || /* CapsLock key has been pressed */
     1384                    IOHIDElementGetUsage(pElementRef) == kHIDUsage_KeypadNumLock)      /* ... or NumLock key has been pressed */
     1385                {
     1386                    Log2(("A modifier key has been pressed\n"));
     1387                    g_LastTouchedState = (VBoxHidLeds_t *)pData;
     1388                }
     1389
     1390    }
    13821391}
    13831392
     
    14621471    CFRunLoopRemoveSource(CFRunLoopGetCurrent(), pState->pLoopSourceRef, kCFRunLoopDefaultMode);
    14631472    CFRelease(pState->pLoopSourceRef);
     1473    CFRelease(pState->pTapRef);
    14641474}
    14651475
     
    15081518    VBoxHidsState_t *hidsState;
    15091519
    1510     hidsState = (VBoxHidsState_t *)RTMemAllocZ(sizeof(VBoxHidsState_t));
     1520    hidsState = (VBoxHidsState_t *)malloc(sizeof(VBoxHidsState_t));
    15111521    if (hidsState)
    15121522    {
     
    15141524        if (hidsState->hidManagerRef)
    15151525        {
    1516 
    15171526            CFDictionaryRef deviceMatchingDictRef = darwinGetLedDeviceMatchingDictionary();
    15181527            if (deviceMatchingDictRef)
    15191528            {
     1529                IOHIDManagerScheduleWithRunLoop(hidsState->hidManagerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    15201530                IOHIDManagerSetDeviceMatching(hidsState->hidManagerRef, deviceMatchingDictRef);
    15211531
     
    15301540                        /* Get all the available devices and cycle through them. */
    15311541                        hidsState->cDevices = CFSetGetCount(hidDevicesSetRef);
    1532                         hidsState->hidDevicesCollection = (IOHIDDeviceRef *)RTMemAllocZ((size_t)hidsState->cDevices * sizeof(IOHIDDeviceRef));
     1542                        hidsState->hidDevicesCollection = (IOHIDDeviceRef *)malloc((size_t)hidsState->cDevices * sizeof(IOHIDDeviceRef));
    15331543                        if (hidsState->hidDevicesCollection)
    15341544                        {
    1535                             hidsState->hidLedsCollection = (VBoxHidLeds_t *)RTMemAllocZ((size_t)hidsState->cDevices * sizeof(VBoxHidLeds_t));
     1545                            hidsState->hidLedsCollection = (VBoxHidLeds_t *)malloc((size_t)hidsState->cDevices * sizeof(VBoxHidLeds_t));
    15361546                            if (hidsState->hidLedsCollection)
    15371547                            {
     
    15711581                                    if (darwinAddCarbonGlobalKeyPressHandler(hidsState) == 0)
    15721582                                    {
     1583                                        CFRelease(hidDevicesSetRef);
    15731584                                        CFRelease(deviceMatchingDictRef);
    15741585                                        return hidsState;
     
    15761587                                }
    15771588
    1578                                 RTMemFree(hidsState->hidLedsCollection);
     1589                                free(hidsState->hidLedsCollection);
    15791590                            }
    15801591
    1581                             RTMemFree(hidsState->hidDevicesCollection);
     1592                            free(hidsState->hidDevicesCollection);
    15821593                        }
     1594
     1595                        CFRelease(hidDevicesSetRef);
    15831596                    }
    15841597
     
    15941607        }
    15951608
    1596         RTMemFree(hidsState);
     1609        free(hidsState);
    15971610    }
    15981611
     
    16301643            {
    16311644                /* Cycle through supported devices only. */
    1632                 if (darwinHidDeviceSupported(hidsState->hidDevicesCollection[i]))
     1645                if (IOHIDDeviceConformsTo(hidsState->hidDevicesCollection[i], kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)
     1646                 && darwinHidDeviceSupported(hidsState->hidDevicesCollection[i]))
    16331647                {
    16341648                    rc = darwinSetDeviceLedsState(hidsState->hidDevicesCollection[i],
     
    16431657                    }
    16441658
     1659                    IOHIDDeviceUnscheduleFromRunLoop(hidsState->hidDevicesCollection[i], CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    16451660                    IOHIDDeviceRegisterInputValueCallback(hidsState->hidDevicesCollection[i], NULL, NULL);
    1646                     IOHIDDeviceUnscheduleFromRunLoop(hidsState->hidDevicesCollection[i], CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    16471661                }
    16481662            }
     1663
     1664            CFRelease(elementMatchingDict);
    16491665        }
    16501666
    16511667        /* Free resources */
    16521668
    1653         RTMemFree(hidsState->hidLedsCollection);
    1654         RTMemFree(hidsState->hidDevicesCollection);
     1669        free(hidsState->hidLedsCollection);
     1670        free(hidsState->hidDevicesCollection);
    16551671
    16561672        rc = IOHIDManagerClose(hidsState->hidManagerRef, 0);
     
    16581674            Log2(("Warning! Something went wrong in attempt to close HID device manager!\n"));
    16591675
     1676        IOHIDManagerUnscheduleFromRunLoop(hidsState->hidManagerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
     1677
    16601678        CFRelease(hidsState->hidManagerRef);
    16611679
    1662         RTMemFree(hidsState);
     1680        free(hidsState);
    16631681    }
    16641682
    16651683    return rc2;
    1666 #else // !VBOX_WITH_KBD_LEDS_SYNC
     1684#else /* !VBOX_WITH_KBD_LEDS_SYNC */
    16671685    (void)pState;
    16681686    return 0;
     
    16931711        if (deviceMatchingDictRef)
    16941712        {
     1713            IOHIDManagerScheduleWithRunLoop(hidManagerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    16951714            IOHIDManagerSetDeviceMatching(hidManagerRef, deviceMatchingDictRef);
    16961715
     
    17051724                    /* Get all the available devices and cycle through them. */
    17061725                    CFIndex cDevices = CFSetGetCount(hidDevicesSetRef);
    1707                     IOHIDDeviceRef *hidDevicesCollection = (IOHIDDeviceRef *)RTMemAllocZ((size_t)cDevices * sizeof(IOHIDDeviceRef));
     1726                    IOHIDDeviceRef *hidDevicesCollection = (IOHIDDeviceRef *)malloc((size_t)cDevices * sizeof(IOHIDDeviceRef));
    17081727                    if (hidDevicesCollection)
    17091728                    {
     
    17311750                        }
    17321751
    1733                         RTMemFree(hidDevicesCollection);
     1752                        free(hidDevicesCollection);
    17341753                    }
     1754
     1755                    CFRelease(hidDevicesSetRef);
    17351756                }
    17361757
     
    17401761            }
    17411762
     1763            IOHIDManagerUnscheduleFromRunLoop(hidManagerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
     1764
    17421765            CFRelease(deviceMatchingDictRef);
    17431766        }
     
    17451768        CFRelease(hidManagerRef);
    17461769    }
    1747 #else // !VBOX_WITH_KBD_LEDS_SYNC
    1748 
     1770#else /* !VBOX_WITH_KBD_LEDS_SYNC */
    17491771    (void)fNumLockOn;
    17501772    (void)fCapsLockOn;
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