[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : gerry
Repository : xara
Revision   : 1467
Date       : Tue Jul 18 18:00:09 BST 2006

Changed paths:
   M /Trunk/XaraLX/Kernel/ccfile.cpp
   M /Trunk/XaraLX/Kernel/cutop.cpp
   M /Trunk/XaraLX/wxOil/handles.cpp
   M /Trunk/XaraLX/wxOil/memblk.cpp
   M /Trunk/XaraLX/wxOil/memory.cpp

More memory tracking and leak fixes


Diff:
Index: Trunk/XaraLX/Kernel/cutop.cpp
===================================================================
--- Trunk/XaraLX/Kernel/cutop.cpp	(revision 1466)
+++ Trunk/XaraLX/Kernel/cutop.cpp	(revision 1467)
@@ -535,7 +535,6 @@
 
 BOOL OpCopy::Init()
 {
-	TRACE( _T("Warning - OpCut::Init called
") );
 	return (RegisterOpDescriptor(0,
  							_R(IDS_COPYOP),
 							CC_RUNTIME_CLASS(OpCopy),
Index: Trunk/XaraLX/Kernel/ccfile.cpp
===================================================================
--- Trunk/XaraLX/Kernel/ccfile.cpp	(revision 1466)
+++ Trunk/XaraLX/Kernel/ccfile.cpp	(revision 1467)
@@ -4852,6 +4852,7 @@
   	     	return;
 		}		      
 		
+		MemHandle	= BAD_MHANDLE;
 		MemFile		= (BYTE*) pFile;			// Set Memory file pointer
 		CurrentPos  = 0;						// Set Current file position		
 		
@@ -4918,12 +4919,13 @@
 		// report error that file is not closed before destructor call
 		GotError(_R(IDE_MEM_CLOSE_ERROR));
 
-        // Release the memory occupied by the file (only if not reading)
-		if (FileProt != CCMemRead) 
+        // Release any memory block we might have
+		if (MemHandle != BAD_MHANDLE)
+		{
 			ReleaseBlock(MemHandle);
-
-       	return;
-	}		
+			MemHandle = BAD_MHANDLE;
+		}
+	}
 }
 
 /********************************************************************************************
@@ -5579,9 +5581,12 @@
 {
 	IsOpen = FALSE;
 
-    // Release the memory occupied by the file
-	if (FileProt != CCMemRead) 
+    // Release any memory block we might have
+	if (MemHandle != BAD_MHANDLE)
+	{
 		ReleaseBlock(MemHandle);
+		MemHandle = BAD_MHANDLE;
+	}
 }
 
 
Index: Trunk/XaraLX/wxOil/memory.cpp
===================================================================
--- Trunk/XaraLX/wxOil/memory.cpp	(revision 1466)
+++ Trunk/XaraLX/wxOil/memory.cpp	(revision 1467)
@@ -108,11 +108,6 @@
 //#include "memory.h" - in camtypes.h [AUTOMATICALLY REMOVED]
 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
 //#include "memblk.h" - in camtypes.h [AUTOMATICALLY REMOVED]
-#if !defined(__WXMAC__)
-#include <malloc.h>
-#else
-#include <malloc/malloc.h>
-#endif
 
 #if defined(__WXGTK__)
 #include <stdio.h>
@@ -408,7 +403,7 @@
 #endif
 
 	// Get the memory
-	ADDR pNewBlock = (ADDR) malloc(Size);
+	ADDR pNewBlock = (ADDR) CCMalloc(Size);
 
 	// Check for NULL
 	if (pNewBlock==NULL)
@@ -421,7 +416,7 @@
 	if (NewHandle==BAD_MHANDLE)
 	{
 		TRACE( wxT("ClaimBlock - got the memory, but not a handle
") );
-		free(pNewBlock);
+		CCFree(pNewBlock);
 		pNewBlock = NULL;
 	}
 
@@ -465,7 +460,11 @@
 	}
 
 	// It was OK, so free the memory
-	free(Address);
+	CCFree(Address);
+
+	// And release the handle or it never will be
+	ReleaseHandle(Handle);
+
 	return TRUE;
 }
 
@@ -506,15 +505,11 @@
 	}
 
 	// Find out how big the old block was
-#if !defined(__WXMAC__)
-	size_t				Size = _msize(Address);
-#else
-	size_t				Size = malloc_size(Address);
-#endif
+	size_t				Size = CCGetBlockSize(Address);
 	Size += NumBytes;
 
 	// Reallocate the block to the new size
-	ADDR				pNewBlock = (ADDR)realloc(Address, Size);
+	ADDR				pNewBlock = (ADDR)CCRealloc(Address, Size);
 	if( pNewBlock==NULL )
 	{
 		TRACE( wxT("realloc failed in IncreaseBlock
") );
@@ -561,15 +556,11 @@
 	}
 
 	// Find out how big the old block was
-#if !defined(__WXMAC__)
-	size_t				Size = _msize(Address);
-#else
-	size_t				Size = malloc_size(Address);
-#endif
+	size_t				Size = CCGetBlockSize(Address);
 	Size -= NumBytes;
 
 	// Reallocate the block to the new size
-	ADDR pNewBlock = (ADDR) realloc(Address, Size);
+	ADDR pNewBlock = (ADDR) CCRealloc(Address, Size);
 	if (pNewBlock==NULL)
 	{
 		TRACE( wxT("realloc failed in IncreaseBlock
") );
@@ -584,15 +575,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
 /********************************************************************************************
 
 >	DynamicHeap *FindHeap(MHANDLE Handle)
@@ -757,11 +739,7 @@
 	}
 
 	// Extract the size from the block
-#if !defined(__WXMAC__)
-	*Size = _msize(*Address);
-#else
-	*Size = malloc_size(*Address);
-#endif
+	*Size = CCGetBlockSize(*Address);
 
 	// Everything went ok
 	return TRUE;
Index: Trunk/XaraLX/wxOil/handles.cpp
===================================================================
--- Trunk/XaraLX/wxOil/handles.cpp	(revision 1466)
+++ Trunk/XaraLX/wxOil/handles.cpp	(revision 1467)
@@ -203,25 +203,26 @@
 
 void DeinitHandles()
 {   
-#ifdef _ 
+#ifdef _DEBUG
 	// Tell me how many handles were in use at its peak
-	TRACEUSER( "Rik", wxT("%ld Handles were used in total.
"), ElementsInHandleTable );
+	TRACE( wxT("DeinitHandles: Max size of handle table = %ld"), ElementsInHandleTable );
 
 	// Tell everyone about any handles that were not released
 	UINT32 Waste = 0;
 	for (UINT32 n=1; n<ElementsInHandleTable; n++)
 	{	
 		if (HandlesTable[n].Address != BAD_MHANDLE )
+		{
+			TRACE( wxT("Handle %d not released (0x%08x)"), n, HandlesTable[n].Address);
 			Waste++;
+		}
 	}
-	TRACE( wxT("DeinitHandles - %ld Handles had not been released
"), Waste );
+	TRACE( wxT("DeinitHandles: %ld handles not released"), Waste );
 #endif
 	
 	// dealloc the memory we now have from the OS
 	HandlesMemory.DeInit();
 }
-     
-     
 
 
 
@@ -288,6 +289,8 @@
 #ifdef USE_UNIQUE_IDS
 BOOL ReleaseHandle( MHANDLE Handle )
 {
+//	TRACEUSER("Gerry", _T("ReleaseHandle - %d"), Handle);
+
 	// make sure its not garbage
 	ENSURE( (Handle & 0xFFFF) > BAD_MHANDLE, "ReleaseHandle: Handle was bad" );
 	ENSURE( (Handle & 0xFFFF) < ElementsInHandleTable, "ReleaseHandle: Handle was bad" );
@@ -319,6 +322,8 @@
 
 BOOL ReleaseHandle( MHANDLE Handle )
 {
+//	TRACEUSER("Gerry", _T("ReleaseHandle - %d"), Handle);
+
 	// make sure its not garbage
 	ENSURE( Handle > BAD_MHANDLE, "ReleaseHandle: Handle was BAD_MHANDLE" );
 	ENSURE( Handle < ElementsInHandleTable, "ReleaseHandle: Handle was too big" );
@@ -449,6 +454,8 @@
 
 BOOL ReleaseRangeOfHandles( ADDR LowAddr, ADDR HighAddr )
 {
+//	TRACEUSER("Gerry", _T("ReleaseRange - 0x%08x to 0x%08x"), LowAddr, HighAddr);
+
 	// Make sure the params are not rubbish
 	ENSURE( HighAddr > LowAddr, "ReleaseRangeOfHandles: Low Addr is Higher the High Addr" );
 	
@@ -460,22 +467,23 @@
     	Address = HandlesTable[ n ].Address;
 
 		// if it is ok
-    	if (Address != BAD_MHANDLE)
-    	{
-    		if( Address >= LowAddr &&
-    			Address < HighAddr )
-	    	{
-    			// If the address is in the range, release it
-    			HandlesTable[n].Address = PBYTE(BAD_MHANDLE);
+		if (Address != BAD_MHANDLE)
+		{
+			if( Address >= LowAddr &&
+				Address < HighAddr )
+			{
+				// If the address is in the range, release it
+//				TRACEUSER("Gerry", _T("ReleaseRange - releasing %d"), n);
+				HandlesTable[n].Address = PBYTE(BAD_MHANDLE);
 				HandlesInUse --;
 			}
 		}
 	}
-    		
+
     return TRUE;
 }
 
-                        
+
 /*********************************************************************************************
 
 >		MHANDLE ClaimHandle( ADDR Address )
@@ -537,6 +545,7 @@
 				HandlesTable[ Handle ].UniqueID = UniqueID;
 				return MAKEINT32( Handle, UniqueID );
 			#else
+//				TRACEUSER("Gerry", _T("ClaimHandle - %d"), Handle);
 				return Handle;
 			#endif
 		}
Index: Trunk/XaraLX/wxOil/memblk.cpp
===================================================================
--- Trunk/XaraLX/wxOil/memblk.cpp	(revision 1466)
+++ Trunk/XaraLX/wxOil/memblk.cpp	(revision 1467)
@@ -197,11 +197,12 @@
 	LPVOID				pNewPtr;
 	if( bAutoZero )
 	{
-		pNewPtr = calloc( m_RoundedSize, 1 );
+		pNewPtr = CCMalloc( m_RoundedSize );
+		memset(pNewPtr, 0, m_RoundedSize);
 	}
 	else
 	{
-		pNewPtr = malloc( m_RoundedSize );
+		pNewPtr = CCMalloc( m_RoundedSize );
 	}
 		
 	if( pNewPtr == NULL )
@@ -318,7 +319,7 @@
 #if USE_STD_ALLOC
 	if( NULL != m_pMemBlk )
 	{
-		free(  m_pMemBlk );
+		CCFree(  m_pMemBlk );
 		m_pMemBlk = NULL;
 	}
 #elif USE_VM_BLOCKS
@@ -457,10 +458,10 @@
 	if( NewSize == m_RoundedSize )
 		return TRUE;									// if same physical size
 
-	LPVOID				NewPtr = realloc( *Pointer, NewSize );
+	LPVOID				NewPtr = CCRealloc( *Pointer, NewSize );
 	if (NewPtr==NULL)
 	{
-		TRACEUSER( "Andy", wxT("VirtualAlloc growing from %ld to %ld failed
"), OldSize, NewSize);
+		TRACEUSER( "Andy", wxT("CCRealloc growing from %ld to %ld failed
"), OldSize, NewSize);
 		return FALSE;
 	}
 	*Pointer = m_pMemBlk = NewPtr;
@@ -529,10 +530,10 @@
 		return FALSE;
 	}									// if same physical size
 
-	LPVOID				NewPtr = realloc( *Pointer, NewSize );
+	LPVOID				NewPtr = CCRealloc( *Pointer, NewSize );
 	if (NewPtr==NULL)
 	{
-		TRACEUSER( "Andy", wxT("VirtualAlloc growing from %ld to %ld failed
"), OldSize, NewSize);
+		TRACEUSER( "Andy", wxT("CCRealloc growing from %ld to %ld failed
"), OldSize, NewSize);
 		return FALSE;
 	}
 	*Pointer = m_pMemBlk = NewPtr;


Xara