VirtualBox

Changeset 85735 in vbox


Ignore:
Timestamp:
Aug 12, 2020 8:48:55 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139883
Message:

Main/HostUpdateImpl.cpp: Make sure the RTHTTP instance is always destroyed, even in std::bad_alloc and whatnot cases. bugref:7983

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/HostUpdateImpl.h

    r85730 r85735  
    2323
    2424#include "HostUpdateWrap.h"
     25#include <iprt/http.h> /* RTHTTP */
    2526
    2627
     
    5253    HRESULT i_updateCheckTask(UpdateCheckTask *pTask);
    5354    HRESULT i_checkForVBoxUpdate();
     55    HRESULT i_checkForVBoxUpdateInner(RTHTTP hHttp, com::Utf8Str const &strUrl, com::Utf8Str const &strUserAgent,
     56                                      ComPtr<ISystemProperties> const &ptrSystemProperties);
    5457
    5558    /** @name Data members.
  • trunk/src/VBox/Main/src-server/HostUpdateImpl.cpp

    r85734 r85735  
    285285
    286286    // acquire the System Properties interface
    287     ComPtr<ISystemProperties> pSystemProperties;
    288     rc = mVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
     287    ComPtr<ISystemProperties> ptrSystemProperties;
     288    rc = mVirtualBox->COMGETTER(SystemProperties)(ptrSystemProperties.asOutParam());
    289289    if (FAILED(rc))
    290290        return setErrorVrc(rc, tr("%s: IVirtualBox::systemProperties() failed: %Rrc"), __FUNCTION__, rc);
     
    297297    RTTimeToString(RTTimeExplode(&Time, RTTimeNow(&TimeNow)), szTimeStr, sizeof(szTimeStr));
    298298    LogRelFunc(("VBox updating UpdateDate with TimeString = %s\n", szTimeStr));
    299     rc = pSystemProperties->COMSETTER(VBoxUpdateLastCheckDate)(Bstr(szTimeStr).raw());
     299    rc = ptrSystemProperties->COMSETTER(VBoxUpdateLastCheckDate)(Bstr(szTimeStr).raw());
    300300    if (FAILED(rc))
    301301        return rc; // ISystemProperties::setLastCheckDate calls setError() on failure
     
    303303    // Update the queryURL and the VBoxUpdate setting 'VBoxUpdateCount'
    304304    ULONG cVBoxUpdateCount = 0;
    305     rc = pSystemProperties->COMGETTER(VBoxUpdateCount)(&cVBoxUpdateCount);
     305    rc = ptrSystemProperties->COMGETTER(VBoxUpdateCount)(&cVBoxUpdateCount);
    306306    if (FAILED(rc))
    307307        return setErrorVrc(rc, tr("%s: retrieving ISystemProperties::VBoxUpdateCount failed: %Rrc"), __FUNCTION__, rc);
     
    309309    cVBoxUpdateCount++;
    310310
    311     rc = pSystemProperties->COMSETTER(VBoxUpdateCount)(cVBoxUpdateCount);
     311    rc = ptrSystemProperties->COMSETTER(VBoxUpdateCount)(cVBoxUpdateCount);
    312312    if (FAILED(rc))
    313313        return rc; // ISystemProperties::setVBoxUpdateCount calls setError() on failure
     
    316316    // Update the query URL and the VBoxUpdate settings (if necessary) with the 'Target' information.
    317317    VBoxUpdateTarget_T enmTarget = VBoxUpdateTarget_Stable; // default branch is 'stable'
    318     rc = pSystemProperties->COMGETTER(VBoxUpdateTarget)(&enmTarget);
     318    rc = ptrSystemProperties->COMGETTER(VBoxUpdateTarget)(&enmTarget);
    319319    if (FAILED(rc))
    320320        return setErrorVrc(rc, tr("%s: retrieving ISystemProperties::Target failed: %Rrc"), __FUNCTION__, rc);
     
    334334    }
    335335
    336     rc = pSystemProperties->COMSETTER(VBoxUpdateTarget)(enmTarget);
     336    rc = ptrSystemProperties->COMSETTER(VBoxUpdateTarget)(enmTarget);
    337337    if (FAILED(rc))
    338338        return rc; // ISystemProperties::setTarget calls setError() on failure
     
    341341
    342342    /*
    343      * Setup the User-Agent headers for the GET request
     343     * Compose the User-Agent header for the GET request.
    344344     */
    345345    Bstr version;
     
    351351    LogRelFunc(("userAgent = %s\n", strUserAgent.c_str()));
    352352
     353    /*
     354     * Create the HTTP client instance and pass it to a inner worker method to
     355     * ensure proper cleanup.
     356     */
    353357    RTHTTP hHttp = NIL_RTHTTP;
    354358    int vrc = RTHttpCreate(&hHttp);
    355     if (RT_FAILURE(vrc))
    356         return setErrorVrc(vrc, tr("%s: RTHttpCreate() failed: %Rrc"), __FUNCTION__, vrc);
    357 
     359    if (RT_SUCCESS(vrc))
     360    {
     361        try
     362        {
     363            rc = i_checkForVBoxUpdateInner(hHttp, strUrl, strUserAgent, ptrSystemProperties);
     364        }
     365        catch (...)
     366        {
     367            AssertFailed();
     368            rc = E_UNEXPECTED;
     369        }
     370        RTHttpDestroy(hHttp);
     371    }
     372    else
     373        rc = setErrorVrc(vrc, tr("%s: RTHttpCreate() failed: %Rrc"), __FUNCTION__, vrc);
     374    return S_OK;
     375}
     376
     377HRESULT HostUpdate::i_checkForVBoxUpdateInner(RTHTTP hHttp, Utf8Str const &strUrl, Utf8Str const &strUserAgent,
     378                                              ComPtr<ISystemProperties> const &ptrSystemProperties)
     379{
    358380    /// @todo Are there any other headers needed to be added first via RTHttpSetHeaders()?
    359     vrc = RTHttpAddHeader(hHttp, "User-Agent", strUserAgent.c_str(), strUserAgent.length(), RTHTTPADDHDR_F_BACK);
     381    int vrc = RTHttpAddHeader(hHttp, "User-Agent", strUserAgent.c_str(), strUserAgent.length(), RTHTTPADDHDR_F_BACK);
    360382    if (RT_FAILURE(vrc))
    361383        return setErrorVrc(vrc, tr("%s: RTHttpAddHeader() failed: %Rrc (on User-Agent)"), __FUNCTION__, vrc);
     
    365387     */
    366388    ProxyMode_T enmProxyMode;
    367     rc = pSystemProperties->COMGETTER(ProxyMode)(&enmProxyMode);
    368     if (FAILED(rc))
    369         return setErrorVrc(rc, tr("%s: ISystemProperties::proxyMode() failed: %Rrc"), __FUNCTION__, rc);
     389    HRESULT rc = ptrSystemProperties->COMGETTER(ProxyMode)(&enmProxyMode);
     390    if (FAILED(rc))
     391        return setError(rc, tr("%s: ISystemProperties::proxyMode() failed: %Rrc"), __FUNCTION__, rc);
    370392
    371393    if (enmProxyMode == ProxyMode_Manual)
    372394    {
    373395        Bstr strProxyURL;
    374         rc = pSystemProperties->COMGETTER(ProxyURL)(strProxyURL.asOutParam());
     396        rc = ptrSystemProperties->COMGETTER(ProxyURL)(strProxyURL.asOutParam());
    375397        if (FAILED(rc))
    376             return setErrorVrc(rc, tr("%s: ISystemProperties::proxyURL() failed: %Rrc"), __FUNCTION__, rc);
     398            return setError(rc, tr("%s: ISystemProperties::proxyURL() failed: %Rrc"), __FUNCTION__, rc);
    377399        vrc = RTHttpSetProxyByUrl(hHttp, Utf8Str(strProxyURL).c_str());
    378400        if (RT_FAILURE(vrc))
     
    385407            return setErrorVrc(vrc, tr("%s: RTHttpUseSystemProxySettings() failed: %Rrc"), __FUNCTION__, vrc);
    386408    }
     409    else
     410        Assert(enmProxyMode == ProxyMode_NoProxy);
    387411
    388412    /*
     
    395419        return setErrorVrc(vrc, tr("%s: RTHttpGetBinary() failed: %Rrc"), __FUNCTION__, vrc);
    396420
     421    /** @todo this may throw and leak.   */
    397422    RTCList<RTCString> lstHttpReply = RTCString((char *)pvResponse, (size_t)cbResponse).split(" ", RTCString::RemoveEmptyParts);
    398423    RTHttpFreeResponse(pvResponse);
     
    414439        LogRelFunc(("HTTP server reply = %s %s\n", lstHttpReply.at(0).c_str(), lstHttpReply.at(1).c_str()));
    415440    }
    416 
    417     // clean-up HTTP request paperwork
    418     /** @todo r=bird: There is no chance that this would be NIL here unless
    419      *        you've got stack corruption.  Besides, RTHttpDestruct ignores NIL. */
    420     if (hHttp != NIL_RTHTTP)
    421         RTHttpDestroy(hHttp);
    422441
    423442    return S_OK;
Note: See TracChangeset for help on using the changeset viewer.

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