VirtualBox

Changeset 10829

Show
Ignore:
Timestamp:
07/23/08 15:06:20 (3 months ago)
Author:
vboxsync
Message:

Additions/common: small adjustment in guest property reading code

Files:

Legend:

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

    r10825 r10829  
    884884    int rc = VINF_SUCCESS; 
    885885 
    886     /* We leave a bit of space here in case the maximum values are raised. */ 
    887     uint32_t cbBuf = MAX_VALUE_LEN + MAX_FLAGS_LEN + 1024; 
    888     void *pvBuf = RTMemAlloc(cbBuf); 
    889     if (NULL == pvBuf) 
    890     { 
    891         rc = VERR_NO_MEMORY; 
    892         VBoxControlError("Out of memory\n"); 
    893     } 
    894     if (RT_SUCCESS(rc)) 
    895     { 
    896         rc = VbglR3GuestPropConnect(&u32ClientId); 
    897         if (!RT_SUCCESS(rc)) 
    898             VBoxControlError("Failed to connect to the guest property service, error %Rrc\n", rc); 
    899     } 
     886    rc = VbglR3GuestPropConnect(&u32ClientId); 
     887    if (!RT_SUCCESS(rc)) 
     888        VBoxControlError("Failed to connect to the guest property service, error %Rrc\n", rc); 
    900889 
    901890/* 
     
    913902         * enough with buffer space. */ 
    914903        bool finish = false; 
    915         for (int i = 0; (i < 10) && !finish; ++i) 
    916         { 
    917             rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cbBuf, 
    918                                      &pszValue, &u64Timestamp, &pszFlags, 
    919                                      &cbBuf); 
     904        /* We leave a bit of space here in case the maximum values are raised. */ 
     905        void *pvBuf = NULL; 
     906        uint32_t cbBuf = MAX_VALUE_LEN + MAX_FLAGS_LEN + 1024; 
     907        for (unsigned i = 0; (i < 10) && !finish; ++i) 
     908        { 
     909            pvBuf = RTMemRealloc(pvBuf, cbBuf); 
     910            if (NULL == pvBuf) 
     911            { 
     912                rc = VERR_NO_MEMORY; 
     913                VBoxControlError("Out of memory\n"); 
     914            } 
     915            else 
     916                rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cbBuf, 
     917                                         &pszValue, &u64Timestamp, &pszFlags, 
     918                                         &cbBuf); 
    920919            if (VERR_BUFFER_OVERFLOW == rc) 
    921             { 
    922                 pvBuf = RTMemRealloc(pvBuf, cbBuf); 
    923                 if (NULL == pvBuf) 
    924                     rc = VERR_NO_MEMORY; 
    925             } 
    926             if (rc != VERR_BUFFER_OVERFLOW) 
     920                /* Leave a bit of extra space to be safe */ 
     921                cbBuf += 1024; 
     922            else 
    927923                finish = true; 
    928924        } 
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp

    r10816 r10829  
    258258{ 
    259259    int rc = VINF_SUCCESS; 
    260     uint32_t cchBuf = 1024; 
    261     void *pvBuf = RTMemAlloc(cchBuf); 
    262260    char *pszValue = NULL; 
    263261    *ppszValue = NULL; 
    264     if (NULL == pvBuf) 
    265         rc = VERR_NO_MEMORY; 
    266     if (RT_SUCCESS(rc)) 
    267     { 
    268         /* There is a race here between our reading the property size and the 
    269          * host changing the value before we read it.  Try up to ten times and 
    270          * report the problem if that fails. */ 
    271         bool finish = false; 
    272         for (unsigned i = 0; (i < 10) && !finish; ++i) 
    273         { 
     262 
     263    /* There is a race here between our reading the property size and the 
     264     * host changing the value before we read it.  Try up to ten times and 
     265     * report the problem if that fails. */ 
     266    bool finish = false; 
     267    /* We leave a bit of space here in case the maximum value is raised. */ 
     268    uint32_t cchBuf = MAX_VALUE_LEN + 1024; 
     269    void *pvBuf = NULL; 
     270    for (unsigned i = 0; (i < 10) && !finish; ++i) 
     271    { 
     272        pvBuf = RTMemRealloc(pvBuf, cchBuf); 
     273        if (NULL == pvBuf) 
     274            rc = VERR_NO_MEMORY; 
     275        else 
    274276            rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf, 
    275277                                     &pszValue, NULL, NULL, &cchBuf); 
    276             if (VERR_BUFFER_OVERFLOW == rc) 
    277             { 
    278                 pvBuf = RTMemRealloc(pvBuf, cchBuf); 
    279                 if (NULL == pvBuf) 
    280                     rc = VERR_NO_MEMORY; 
    281             } 
    282             if (rc != VERR_BUFFER_OVERFLOW) 
    283                 finish = true; 
    284         } 
    285278        if (VERR_BUFFER_OVERFLOW == rc) 
    286             /* VERR_BUFFER_OVERFLOW has a different meaning here as a 
    287              * return code, but we need to report the race. */ 
    288             rc = VERR_TOO_MUCH_DATA; 
    289     } 
     279            /* Leave a bit of extra space to be safe */ 
     280            cchBuf += 1024; 
     281        else 
     282            finish = true; 
     283    } 
     284    if (VERR_BUFFER_OVERFLOW == rc) 
     285        /* VERR_BUFFER_OVERFLOW has a different meaning here as a 
     286         * return code, but we need to report the race. */ 
     287        rc = VERR_TOO_MUCH_DATA; 
    290288    if (RT_SUCCESS(rc)) 
    291289        *ppszValue = pszValue; 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy