VirtualBox

Changeset 31372 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 4, 2010 7:01:08 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64429
Message:

Main: fix memory leak in VirtualBox::postEvent() when posting the event fails

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31370 r31372  
    19331933 *  method call.
    19341934 *
    1935  *  @param event    event to post
    1936  *                  (must be allocated using |new|, will be deleted automatically
    1937  *                  by the event thread after processing)
     1935 *  @param event    event to post; must have been allocated using |new|, will
     1936 *                  be deleted automatically by the event thread after processing
    19381937 *
    19391938 *  @note Doesn't lock any object.
     
    19411940HRESULT VirtualBox::postEvent(Event *event)
    19421941{
    1943     AutoCaller autoCaller(this);
    1944     AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    1945 
    1946     if (autoCaller.state() != Ready)
    1947     {
    1948         LogWarningFunc(("VirtualBox has been uninitialized (state=%d), the event is discarded!\n",
    1949                         autoCaller.state()));
    1950         return S_OK;
    1951     }
    1952 
    19531942    AssertReturn(event, E_FAIL);
    1954     AssertReturn(m->pAsyncEventQ, E_FAIL);
    1955 
    1956     if (m->pAsyncEventQ->postEvent(event))
    1957         return S_OK;
    1958 
    1959     return E_FAIL;
     1943
     1944    HRESULT rc;
     1945    AutoCaller autoCaller(this);
     1946    if (SUCCEEDED((rc = autoCaller.rc())))
     1947    {
     1948        if (autoCaller.state() != Ready)
     1949            LogWarningFunc(("VirtualBox has been uninitialized (state=%d), the event is discarded!\n",
     1950                            autoCaller.state()));
     1951            // return S_OK
     1952        else if (    (m->pAsyncEventQ)
     1953                  && (m->pAsyncEventQ->postEvent(event))
     1954                )
     1955            return S_OK;
     1956        else
     1957            rc = E_FAIL;
     1958    }
     1959
     1960    // in any event of failure, we must clean up here, or we'll leak;
     1961    // the caller has allocated the object using new()
     1962    delete event;
     1963    return rc;
    19601964}
    19611965
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