VirtualBox

Changeset 5522 in vbox for trunk/src/libs


Ignore:
Timestamp:
Oct 26, 2007 5:21:00 PM (17 years ago)
Author:
vboxsync
Message:

XPCOM: Fixed memory errors and leaks found by valgrind.

Location:
trunk/src/libs/xpcom18a4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/ipc/ipcd/client/src/ipcdclient.cpp

    r3373 r5522  
    11981198  td->pendingQ.Append(msg);
    11991199
    1200   LOG(("placed message on pending queue for target %s and notifying all...\n", target.ToString()));
     1200#ifdef IPC_LOGGING
     1201  {
     1202    char *targetStr = target.ToString();
     1203    LOG(("placed message on pending queue for target %s and notifying all...\n", targetStr));
     1204    nsMemory::Free(targetStr);
     1205  }
     1206#endif
    12011207
    12021208  // wake up anyone waiting on this queue
     
    12771283        nsAutoMonitor mon(gClientState->monitor);
    12781284        gClientState->targetMap.EnumerateRead(EnumerateTargetMapAndPlaceMsg, msg);
     1285
     1286        delete msg;
    12791287       
    12801288        return;
  • 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
  • trunk/src/libs/xpcom18a4/xpcom/base/nsExceptionService.cpp

    r1 r5522  
    8484#ifdef NS_DEBUG
    8585  inline nsrefcnt ReleaseQuiet() {
    86       nsAutoOwningThread old = _mOwningThread;
    87       _mOwningThread = nsAutoOwningThread();
    88       nsrefcnt ref = Release();
     86    // shut up NS_ASSERT_OWNINGTHREAD (see explaination below)
     87    nsAutoOwningThread old = _mOwningThread;
     88    _mOwningThread = nsAutoOwningThread();
     89    nsrefcnt ref = Release();
     90    NS_ASSERTION(ref == 0, "the object is still referenced by other threads while it shouldn't");
     91    if (ref != 0)
    8992      _mOwningThread = old;
    90       return ref;
     93    return ref;
    9194  }
    9295#else 
     
    103106#endif
    104107
    105 // Note this object is single threaded - the service itself ensures
    106 // one per thread.
    107 // Exceptions are DropAllThreads (called on the thread shutting down xpcom)
    108 // and ThreadDestruct (called after xpcom destroyed the internal thread struct,
    109 // so that PR_GetCurrentThread() will create a new one from scratch which will
    110 // obviously not match the old one stored in the instance on creation). Since
    111 // these NS_CheckThreadSafe() assertions are quite annoying in the debug build,
    112 // we use a special ReleaseQuiet() mehtod in DoDropThread() to shut them up.
     108// Note: the nsExceptionManager object is single threaded - the exception
     109// service itself ensures one per thread. However, there are two methods that
     110// may be called on foreign threads: DropAllThreads (called on the thread
     111// shutting down xpcom) and ThreadDestruct (called after xpcom destroyed the
     112// internal thread struct, so that PR_GetCurrentThread() will create a new one
     113// from scratch which will obviously not match the old one stored in the
     114// instance on creation). In both cases, there should be no other threads
     115// holding objects (i.e. it's thread-safe to call them), but
     116// NS_CheckThreadSafe() assertions will still happen and yell in the debug
     117// build. Since it is quite annoying, we use a special ReleaseQuiet() mehtod
     118// in DoDropThread() to shut them up.
    113119NS_IMPL_ISUPPORTS1(nsExceptionManager, nsIExceptionManager)
    114120
  • trunk/src/libs/xpcom18a4/xpcom/glue/nsDebug.cpp

    r1 r5522  
    4444static nsIDebug* gDebugObject = nsnull;
    4545
     46// Note: Although the machinery here is similar to nsMemory.cpp, we cannot use
     47// NS_ASSERTION macros below because they end up in nsDebug::Assertion and
     48// therefore may produce endless recursion.
     49
    4650static NS_METHOD FreeDebugObject(void)
    4751{
     
    5559static nsIDebug* SetupDebugObject()
    5660{
    57   NS_GetDebug(&gDebugObject);
    58   if (gDebugObject)
    59     NS_RegisterXPCOMExitRoutine(FreeDebugObject, 0);
     61  if (!gDebugObject)
     62  {
     63    NS_GetDebug(&gDebugObject);
     64    if (gDebugObject)
     65      NS_RegisterXPCOMExitRoutine(FreeDebugObject, 0);
     66  }
    6067  return gDebugObject;
    6168}
     
    6471nsresult GlueStartupDebug()
    6572{
    66   NS_GetDebug(&gDebugObject);
    67   if (!gDebugObject)
    68     return NS_ERROR_FAILURE;
     73  if (!gDebugObject)
     74  {
     75    NS_GetDebug(&gDebugObject);
     76    if (!gDebugObject)
     77      return NS_ERROR_FAILURE;
     78  }
    6979  return NS_OK;
    7080}
  • trunk/src/libs/xpcom18a4/xpcom/glue/nsMemory.cpp

    r1 r5522  
    4444static NS_METHOD FreeGlobalMemory(void)
    4545{
     46    NS_ASSERTION(gMemory, "must be not null after SetupGlobalMemory");
    4647    NS_IF_RELEASE(gMemory);
    4748    return NS_OK;
     
    5455SetupGlobalMemory()
    5556{
    56     NS_ASSERTION(!gMemory, "bad call");
    57     NS_GetMemoryManager(&gMemory);
    58     NS_ASSERTION(gMemory, "can't get memory manager!");
    59     NS_RegisterXPCOMExitRoutine(FreeGlobalMemory, 0);
     57    NS_ASSERTION(!gMemory, "must be called once");
     58    if (!gMemory)
     59    {
     60        NS_GetMemoryManager(&gMemory);
     61        NS_ASSERTION(gMemory, "can't get memory manager!");
     62        if (gMemory)
     63            NS_RegisterXPCOMExitRoutine(FreeGlobalMemory, 0);
     64    }
    6065    return gMemory;
    6166}
     
    6469nsresult GlueStartupMemory()
    6570{
    66     NS_ASSERTION(!gMemory, "bad call");
    67     NS_GetMemoryManager(&gMemory);
    68     NS_ASSERTION(gMemory, "can't get memory manager!");
     71    NS_ASSERTION(!gMemory, "must be called once");
     72    if (!gMemory)
     73    {
     74        NS_GetMemoryManager(&gMemory);
     75        NS_ASSERTION(gMemory, "can't get memory manager!");
     76        if (!gMemory)
     77            return NS_ERROR_FAILURE;
     78    }
    6979    return NS_OK;
    7080}
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