VirtualBox

Ignore:
Timestamp:
Oct 26, 2007 5:21:00 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
25742
Message:

XPCOM: Fixed memory errors and leaks found by valgrind.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src/ipcDConnectService.cpp

    r4863 r5522  
    122122// dconnect minor opcodes for INVOKE
    123123
     124#pragma pack(1)
     125
    124126struct DConnectOp
    125127{
     
    186188  // (see ipcDConnectService::SerializeException)
    187189};
     190
     191#pragma pack()
    188192
    189193//-----------------------------------------------------------------------------
     
    471475    case nsXPTType::T_IID:
    472476      {
    473         nsID *buf = (nsID *) malloc(sizeof(nsID));
     477        nsID *buf = (nsID *) nsMemory::Alloc(sizeof(nsID));
    474478        reader.GetBytes(buf, sizeof(nsID));
    475479        v.val.p = v.ptr = buf;
     
    489493        else
    490494        {
    491           char *buf = (char *) malloc(len + 1);
     495          char *buf = (char *) nsMemory::Alloc(len + 1);
    492496          reader.GetBytes(buf, len);
    493497          buf[len] = char(0);
     
    510514        else
    511515        {
    512           PRUnichar *buf = (PRUnichar *) malloc(len + 2);
     516          PRUnichar *buf = (PRUnichar *) nsMemory::Alloc(len + 2);
    513517          reader.GetBytes(buf, len);
    514518          buf[len / 2] = PRUnichar(0);
     
    621625    v.type = t;
    622626    v.flags = nsXPTCVariant::PTR_IS_DATA;
     627
     628    // nsID, string and wstring types are not understood as dippers (see
     629    // DIPPER_TYPE in xpidl.h) but they behave like dippers too. Therefore we
     630    // need to treat them so manually.
     631    switch (t.TagPart())
     632    {
     633      case nsXPTType::T_IID:
     634      case nsXPTType::T_CHAR_STR:
     635      case nsXPTType::T_WCHAR_STR:
     636        // add VAL_IS_ALLOCD to cause FinishParam() to do cleanup
     637        v.flags |= nsXPTCVariant::VAL_IS_ALLOCD;
     638        break;
     639      default:
     640        break;
     641    }
    623642  }
    624643
     
    633652
    634653  if (v.IsValAllocated())
    635     free(v.val.p);
     654      nsMemory::Free(v.val.p);
    636655  else if (v.IsValInterface())
    637656    ((nsISupports *) v.val.p)->Release();
     
    17861805
    17871806    // check if this object is nsISupports itself
    1788     nsIID *iid = 0;
    1789     rv = mIInfo->GetInterfaceIID(&iid);
    1790     NS_ASSERTION(NS_SUCCEEDED(rv) && iid,
    1791                  "nsIInterfaceInfo::GetInterfaceIID failed");
    1792     if (NS_SUCCEEDED(rv) && iid &&
    1793         iid->Equals(NS_GET_IID(nsISupports)))
    1794     {
    1795       // nsISupports is queried on nsISupports, return ourselves
    1796       *aInstancePtr = this;
    1797       NS_ADDREF_THIS();
    1798       // cache ourselves weakly
    1799       mCachedISupports = this;
    1800 
    1801       PR_Unlock(dConnect->StubQILock());
    1802       return NS_OK;
     1807    {
     1808      nsIID *iid = 0;
     1809      rv = mIInfo->GetInterfaceIID(&iid);
     1810      NS_ASSERTION(NS_SUCCEEDED(rv) && iid,
     1811                   "nsIInterfaceInfo::GetInterfaceIID failed");
     1812      if (NS_SUCCEEDED(rv) && iid &&
     1813          iid->Equals(NS_GET_IID(nsISupports)))
     1814      {
     1815        nsMemory::Free((void*)iid);
     1816
     1817        // nsISupports is queried on nsISupports, return ourselves
     1818        *aInstancePtr = this;
     1819        NS_ADDREF_THIS();
     1820        // cache ourselves weakly
     1821        mCachedISupports = this;
     1822
     1823        PR_Unlock(dConnect->StubQILock());
     1824        return NS_OK;
     1825      }
     1826      if (iid)
     1827        nsMemory::Free((void*)iid);
    18031828    }
    18041829
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