VirtualBox

Changeset 10859 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Jul 24, 2008 4:43:29 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
33675
Message:

VBoxControl: Fixed incorrect RTMemFree.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp

    r10834 r10859  
    5454 * Displays the program usage message.
    5555 *
    56  * @param u64Which 
    57  * 
     56 * @param u64Which
     57 *
    5858 * @{
    59  */ 
     59 */
    6060
    6161/** Helper function */
     
    190190    paNewRects[iResized].right += NewWidth - (paNewRects[iResized].right - paNewRects[iResized].left);
    191191    paNewRects[iResized].bottom += NewHeight - (paNewRects[iResized].bottom - paNewRects[iResized].top);
    192    
    193     /* Verify all pairs of originally adjacent rectangles for all 4 directions. 
     192
     193    /* Verify all pairs of originally adjacent rectangles for all 4 directions.
    194194     * If the pair has a "good" delta (that is the first rectangle intersects the second)
    195195     * at a direction and the second rectangle is not primary one (which can not be moved),
    196196     * move the second rectangle to make it adjacent to the first one.
    197197     */
    198    
     198
    199199    /* X positive. */
    200200    unsigned iRect;
     
    204204        unsigned iNextRect = nextAdjacentRectXP (paRects, nRects, iRect);
    205205        Log(("next %d -> %d\n", iRect, iNextRect));
    206        
     206
    207207        if (iNextRect == ~0 || iNextRect == iPrimary)
    208208        {
    209209            continue;
    210210        }
    211        
     211
    212212        /* Check whether there is an X intesection between these adjacent rects in the new rectangles
    213213         * and fix the intersection if delta is "good".
    214214         */
    215215        int delta = paNewRects[iRect].right - paNewRects[iNextRect].left;
    216        
     216
    217217        if (delta > 0)
    218218        {
     
    220220                     paNewRects[iRect].right, paNewRects[iNextRect].left,
    221221                     delta));
    222            
     222
    223223            paNewRects[iNextRect].left += delta;
    224224            paNewRects[iNextRect].right += delta;
    225225        }
    226226    }
    227    
     227
    228228    /* X negative. */
    229229    for (iRect = 0; iRect < nRects; iRect++)
     
    232232        unsigned iNextRect = nextAdjacentRectXN (paRects, nRects, iRect);
    233233        Log(("next %d -> %d\n", iRect, iNextRect));
    234        
     234
    235235        if (iNextRect == ~0 || iNextRect == iPrimary)
    236236        {
    237237            continue;
    238238        }
    239        
     239
    240240        /* Check whether there is an X intesection between these adjacent rects in the new rectangles
    241241         * and fix the intersection if delta is "good".
    242242         */
    243243        int delta = paNewRects[iRect].left - paNewRects[iNextRect].right;
    244        
     244
    245245        if (delta < 0)
    246246        {
     
    248248                     paNewRects[iRect].left, paNewRects[iNextRect].right,
    249249                     delta));
    250            
     250
    251251            paNewRects[iNextRect].left += delta;
    252252            paNewRects[iNextRect].right += delta;
    253253        }
    254254    }
    255    
     255
    256256    /* Y positive (in the computer sence, top->down). */
    257257    for (iRect = 0; iRect < nRects; iRect++)
     
    260260        unsigned iNextRect = nextAdjacentRectYP (paRects, nRects, iRect);
    261261        Log(("next %d -> %d\n", iRect, iNextRect));
    262        
     262
    263263        if (iNextRect == ~0 || iNextRect == iPrimary)
    264264        {
    265265            continue;
    266266        }
    267        
     267
    268268        /* Check whether there is an Y intesection between these adjacent rects in the new rectangles
    269269         * and fix the intersection if delta is "good".
    270270         */
    271271        int delta = paNewRects[iRect].bottom - paNewRects[iNextRect].top;
    272        
     272
    273273        if (delta > 0)
    274274        {
     
    276276                     paNewRects[iRect].bottom, paNewRects[iNextRect].top,
    277277                     delta));
    278            
     278
    279279            paNewRects[iNextRect].top += delta;
    280280            paNewRects[iNextRect].bottom += delta;
    281281        }
    282282    }
    283    
     283
    284284    /* Y negative (in the computer sence, down->top). */
    285285    for (iRect = 0; iRect < nRects; iRect++)
     
    288288        unsigned iNextRect = nextAdjacentRectYN (paRects, nRects, iRect);
    289289        Log(("next %d -> %d\n", iRect, iNextRect));
    290        
     290
    291291        if (iNextRect == ~0 || iNextRect == iPrimary)
    292292        {
    293293            continue;
    294294        }
    295        
     295
    296296        /* Check whether there is an Y intesection between these adjacent rects in the new rectangles
    297297         * and fix the intersection if delta is "good".
    298298         */
    299299        int delta = paNewRects[iRect].top - paNewRects[iNextRect].bottom;
    300        
     300
    301301        if (delta < 0)
    302302        {
     
    304304                     paNewRects[iRect].top, paNewRects[iNextRect].bottom,
    305305                     delta));
    306            
     306
    307307            paNewRects[iNextRect].top += delta;
    308308            paNewRects[iNextRect].bottom += delta;
    309309        }
    310310    }
    311    
     311
    312312    memcpy (paRects, paNewRects, sizeof (RECTL) * nRects);
    313313    return;
     
    318318{
    319319    BOOL fModeReset = (Width == 0 && Height == 0 && BitsPerPixel == 0);
    320    
     320
    321321    DISPLAY_DEVICE DisplayDevice;
    322322
    323323    ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
    324324    DisplayDevice.cb = sizeof(DisplayDevice);
    325    
     325
    326326    /* Find out how many display devices the system has */
    327327    DWORD NumDevices = 0;
    328328    DWORD i = 0;
    329329    while (EnumDisplayDevices (NULL, i, &DisplayDevice, 0))
    330     { 
     330    {
    331331        Log(("[%d] %s\n", i, DisplayDevice.DeviceName));
    332332
     
    338338        else if (!(DisplayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))
    339339        {
    340            
     340
    341341            Log(("Found secondary device. err %d\n", GetLastError ()));
    342342            NumDevices++;
    343343        }
    344        
     344
    345345        ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
    346346        DisplayDevice.cb = sizeof(DisplayDevice);
    347347        i++;
    348348    }
    349    
     349
    350350    Log(("Found total %d devices. err %d\n", NumDevices, GetLastError ()));
    351    
     351
    352352    if (NumDevices == 0 || Id >= NumDevices)
    353353    {
     
    355355        return FALSE;
    356356    }
    357    
     357
    358358    DISPLAY_DEVICE *paDisplayDevices = (DISPLAY_DEVICE *)alloca (sizeof (DISPLAY_DEVICE) * NumDevices);
    359359    DEVMODE *paDeviceModes = (DEVMODE *)alloca (sizeof (DEVMODE) * NumDevices);
    360360    RECTL *paRects = (RECTL *)alloca (sizeof (RECTL) * NumDevices);
    361    
     361
    362362    /* Fetch information about current devices and modes. */
    363363    DWORD DevNum = 0;
    364364    DWORD DevPrimaryNum = 0;
    365    
     365
    366366    ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE));
    367367    DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
    368    
     368
    369369    i = 0;
    370370    while (EnumDisplayDevices (NULL, i, &DisplayDevice, 0))
    371     { 
     371    {
    372372        Log(("[%d(%d)] %s\n", i, DevNum, DisplayDevice.DeviceName));
    373        
     373
    374374        BOOL bFetchDevice = FALSE;
    375375
     
    382382        else if (!(DisplayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))
    383383        {
    384            
     384
    385385            Log(("Found secondary device. err %d\n", GetLastError ()));
    386386            bFetchDevice = TRUE;
    387387        }
    388        
     388
    389389        if (bFetchDevice)
    390390        {
     
    394394                return FALSE;
    395395            }
    396        
     396
    397397            paDisplayDevices[DevNum] = DisplayDevice;
    398            
     398
    399399            ZeroMemory(&paDeviceModes[DevNum], sizeof(DEVMODE));
    400400            paDeviceModes[DevNum].dmSize = sizeof(DEVMODE);
     
    405405                return FALSE;
    406406            }
    407            
     407
    408408            Log(("%dx%d at %d,%d\n",
    409409                    paDeviceModes[DevNum].dmPelsWidth,
     
    411411                    paDeviceModes[DevNum].dmPosition.x,
    412412                    paDeviceModes[DevNum].dmPosition.y));
    413                    
     413
    414414            paRects[DevNum].left   = paDeviceModes[DevNum].dmPosition.x;
    415415            paRects[DevNum].top    = paDeviceModes[DevNum].dmPosition.y;
     
    418418            DevNum++;
    419419        }
    420        
     420
    421421        ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE));
    422422        DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
    423423        i++;
    424424    }
    425    
     425
    426426    if (Width == 0)
    427427    {
     
    454454    }
    455455#endif /* Log */
    456    
     456
    457457    /* Without this, Windows will not ask the miniport for its
    458458     * mode table but uses an internal cache instead.
     
    470470        paDeviceModes[i].dmPelsWidth  = paRects[i].right - paRects[i].left;
    471471        paDeviceModes[i].dmPelsHeight = paRects[i].bottom - paRects[i].top;
    472        
     472
    473473        paDeviceModes[i].dmFields = DM_POSITION | DM_PELSHEIGHT | DM_PELSWIDTH;
    474        
     474
    475475        if (   i == Id
    476476            && BitsPerPixel != 0)
     
    479479            paDeviceModes[i].dmBitsPerPel = BitsPerPixel;
    480480        }
    481         Log(("calling pfnChangeDisplaySettingsEx %x\n", gpfnChangeDisplaySettingsEx));     
    482         gpfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName, 
    483                  &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL); 
     481        Log(("calling pfnChangeDisplaySettingsEx %x\n", gpfnChangeDisplaySettingsEx));
     482        gpfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName,
     483                 &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL);
    484484        Log(("ChangeDisplaySettings position err %d\n", GetLastError ()));
    485485    }
    486    
     486
    487487    /* A second call to ChangeDisplaySettings updates the monitor. */
    488     LONG status = ChangeDisplaySettings(NULL, 0); 
     488    LONG status = ChangeDisplaySettings(NULL, 0);
    489489    Log(("ChangeDisplaySettings update status %d\n", status));
    490490    if (status == DISP_CHANGE_SUCCESSFUL || status == DISP_CHANGE_BADMODE)
     
    522522        *(uintptr_t *)&gpfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
    523523        Log(("VBoxService: pChangeDisplaySettingsEx = %p\n", gpfnChangeDisplaySettingsEx));
    524        
     524
    525525        if (gpfnChangeDisplaySettingsEx)
    526526        {
    527527            /* The screen index is 0 based in the ResizeDisplayDevice call. */
    528528            scr = scr > 0? scr - 1: 0;
    529            
     529
    530530            /* Horizontal resolution must be a multiple of 8, round down. */
    531531            xres &= ~0x7;
     
    891891 * Here we actually retrieve the value from the host.
    892892 */
     893    void *pvBuf = NULL;
    893894    const char *pszName = argv[0];
    894895    char *pszValue = NULL;
     
    903904        bool finish = false;
    904905        /* We leave a bit of space here in case the maximum values are raised. */
    905         void *pvBuf = NULL;
    906906        uint32_t cbBuf = MAX_VALUE_LEN + MAX_FLAGS_LEN + 1024;
    907907        for (unsigned i = 0; (i < 10) && !finish; ++i)
     
    910910            if (NULL == pvTmpBuf)
    911911            {
    912                 RTMemFree(pvBuf);
    913912                rc = VERR_NO_MEMORY;
    914913                VBoxControlError("Out of memory\n");
     
    937936    if (VERR_NOT_FOUND == rc)
    938937        RTPrintf("No value set!\n");
    939     if (RT_SUCCESS(rc))
     938    else if (RT_SUCCESS(rc))
     939    {
    940940        RTPrintf("Value: %S\n", pszValue);
    941     if (RT_SUCCESS(rc) && verbose)
    942     {
    943         RTPrintf("Timestamp: %lld ns\n", u64Timestamp);
    944         RTPrintf("Flags: %S\n", pszFlags);
     941        if (verbose)
     942        {
     943            RTPrintf("Timestamp: %lld ns\n", u64Timestamp);
     944            RTPrintf("Flags: %S\n", pszFlags);
     945        }
    945946    }
    946947
    947948    if (u32ClientId != 0)
    948949        VbglR3GuestPropDisconnect(u32ClientId);
     950    RTMemFree(pvBuf);
    949951    return RT_SUCCESS(rc) ? 0 : 1;
    950952}
     
    11121114            onlyinfo = true;
    11131115            dohelp = true;
    1114             done = true;           
     1116            done = true;
    11151117        }
    11161118        else
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