0023006: Improvement to debug memory leaks and insufficient memory growths.
authorskv <skv@opencascade.com>
Mon, 12 Mar 2012 15:05:53 +0000 (19:05 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 15 Mar 2012 08:17:48 +0000 (12:17 +0400)
src/OSD/OSD_MAllocHook.cxx
src/OSD/OSD_MAllocHook.hxx

index 1b4594b..f2485f5 100755 (executable)
@@ -470,16 +470,14 @@ Standard_Boolean OSD_MAllocHook::CollectBySize::MakeReport(const char* theOutFil
   Standard_Size aTotAlloc = 0;
   for (int i = 0; i < MAX_ALLOC_SIZE; i++)
   {
-    if (myArray[i].nbAlloc > 0)
+    if (myArray[i].nbAlloc > 0 || myArray[i].nbFree > 0)
     {
       Standard_Integer nbLeft = myArray[i].nbAlloc - myArray[i].nbFree;
-      if (nbLeft < 0)
-        nbLeft = 0;
       int aSize = i + 1;
       Standard_Size aSizeAlloc = myArray[i].nbAlloc * aSize;
-      Standard_Size aSizeLeft = nbLeft * aSize;
+      ptrdiff_t     aSizeLeft = nbLeft * aSize;
       Standard_Size aSizePeak = myArray[i].nbLeftPeak * aSize;
-      fprintf(aRepFile, "%10d %10d %10d %10d %10Iu %10Iu %10Iu\n", aSize,
+      fprintf(aRepFile, "%10d %10d %10d %10d %10Iu %10Id %10Iu\n", aSize,
               myArray[i].nbAlloc, nbLeft, myArray[i].nbLeftPeak,
               aSizeAlloc, aSizeLeft, aSizePeak);
       if (aTotAlloc + aSizeAlloc < aTotAlloc) // overflow ?
@@ -488,7 +486,7 @@ Standard_Boolean OSD_MAllocHook::CollectBySize::MakeReport(const char* theOutFil
         aTotAlloc += aSizeAlloc;
     }
   }
-  fprintf(aRepFile, "%10s %10s %10s %10s%c%10Iu %10Iu %10Iu\n", "Total:",
+  fprintf(aRepFile, "%10s %10s %10s %10s%c%10Iu %10Id %10Iu\n", "Total:",
           "", "", "", (aTotAlloc == SIZE_MAX ? '>' : ' '), aTotAlloc,
           myTotalLeftSize, myTotalPeakSize);
   fclose(aRepFile);
@@ -512,13 +510,12 @@ void OSD_MAllocHook::CollectBySize::AllocEvent
   {
     myMutex.Lock();
     int ind = (theSize > MAX_ALLOC_SIZE ? MAX_ALLOC_SIZE-1 : (int)(theSize-1));
-    if (myArray[ind].nbAlloc + 1 > 0)
-      myArray[ind].nbAlloc++;
+    myArray[ind].nbAlloc++;
     myTotalLeftSize += theSize;
     int nbLeft = myArray[ind].nbAlloc - myArray[ind].nbFree;
     if (nbLeft > myArray[ind].nbLeftPeak)
       myArray[ind].nbLeftPeak = nbLeft;
-    if (myTotalLeftSize > myTotalPeakSize)
+    if (myTotalLeftSize > (ptrdiff_t)myTotalPeakSize)
       myTotalPeakSize = myTotalLeftSize;
     myMutex.Unlock();
   }
@@ -534,12 +531,11 @@ void OSD_MAllocHook::CollectBySize::FreeEvent
                     size_t      theSize,
                     long        /*theRequestNum*/)
 {
-  if (theSize > 0 && myTotalLeftSize >= theSize)
+  if (theSize > 0)
   {
     myMutex.Lock();
     int ind = (theSize > MAX_ALLOC_SIZE ? MAX_ALLOC_SIZE-1 : (int)(theSize-1));
-    if (myArray[ind].nbFree + 1 > 0)
-      myArray[ind].nbFree++;
+    myArray[ind].nbFree++;
     myTotalLeftSize -= theSize;
     myMutex.Unlock();
   }
index 4edd59b..e24692e 100755 (executable)
@@ -128,7 +128,7 @@ public:
 
     Standard_Mutex myMutex;
     Numbers*       myArray;
-    size_t         myTotalLeftSize;
+    ptrdiff_t      myTotalLeftSize;
     size_t         myTotalPeakSize;
     size_t         myBreakSize;
   };