[xiph-commits] r8040 - in trunk/oggdsf/src: lib/core/ogg/libOOOgg tools/iTranscode

illiminable at motherfish-iii.xiph.org illiminable at motherfish-iii.xiph.org
Sun Oct 17 08:48:14 PDT 2004


Author: illiminable
Date: 2004-10-17 08:48:13 -0700 (Sun, 17 Oct 2004)
New Revision: 8040

Modified:
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.cpp
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp
   trunk/oggdsf/src/tools/iTranscode/iTranscode.cpp
Log:
* Started leak checking.
* Removed a few leaks from the main demux class.
* Circular Buffer and OggDataBuffer now leak free.

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp	2004-10-17 11:21:14 UTC (rev 8039)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp	2004-10-17 15:48:13 UTC (rev 8040)
@@ -1,6 +1,7 @@
 #include "StdAfx.h"
 #include ".\circularbuffer.h"
 
+//Leak checked : 20041017 - OK
 CircularBuffer::CircularBuffer(unsigned long inBufferSize)
 	:	mBufferSize(inBufferSize)
 	,	mBuffer(NULL)
@@ -8,7 +9,7 @@
 	,	mWritePtr(0)
 
 {
-	mBuffer = new unsigned char[inBufferSize + 1];
+	mBuffer = new unsigned char[inBufferSize + 1];			//Deleted in destructor.
 }
 
 CircularBuffer::~CircularBuffer(void)

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h	2004-10-17 11:21:14 UTC (rev 8039)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h	2004-10-17 15:48:13 UTC (rev 8040)
@@ -116,4 +116,8 @@
 
 	void bufASSERT(bool inBool) {	if (!inBool) throw 0; };
 	unsigned char* mBuffer;
+
+private:
+	CircularBuffer& operator=(const CircularBuffer& other);  /* Don't assign me */
+	CircularBuffer(const CircularBuffer& other); /* Don't copy me */
 };

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-10-17 11:21:14 UTC (rev 8039)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-10-17 15:48:13 UTC (rev 8040)
@@ -32,11 +32,13 @@
 #include "StdAfx.h"
 #include ".\oggdatabuffer.h"
 
+
+//LEAK CHECKED - 2004/10/17		-	OK.
 OggDataBuffer::OggDataBuffer(void)
 	:	mBuffer(NULL)
 	,	mPrevGranPos(0)
 {
-	mBuffer = new CircularBuffer(MAX_OGG_PAGE_SIZE);
+	mBuffer = new CircularBuffer(MAX_OGG_PAGE_SIZE);			//Deleted in destructor
 
 	//debugLog.open("G:\\logs\\OggDataBuffer.log", ios_base::out);
 	pendingPage = NULL;
@@ -49,7 +51,7 @@
 	:	mBuffer(NULL)
 	,	mPrevGranPos(0)
 {
-	mBuffer = new CircularBuffer(MAX_OGG_PAGE_SIZE);
+	mBuffer = new CircularBuffer(MAX_OGG_PAGE_SIZE);			//Deleted in destructor
 
 	//debugLog.open("G:\\logs\\OggDataBufferSeek.log", ios_base::out);
 	pendingPage = NULL;
@@ -60,7 +62,7 @@
 
 OggDataBuffer::~OggDataBuffer(void)
 {
-	delete[] mBuffer;
+	delete mBuffer;
 	//debugLog.close();
 	delete pendingPage;
 }
@@ -100,6 +102,7 @@
 	//returns the state of the stream
 	return mState;
 }
+//This function accepts the responsibility for the incoming page.
 OggDataBuffer::eDispatchResult OggDataBuffer::dispatch(OggPage* inOggPage) {
 	//TODO::: Who owns this pointer inOggPage ?
 	//debugLog<<"Dispatching page..."<<endl<<endl;
@@ -167,10 +170,10 @@
 		delete pendingPage;
 		
 		//Make a fresh ogg page
-		pendingPage = new OggPage;
+		pendingPage = new OggPage;			//Either deleted in destructor, or given away by virtue of dispatch method.
 
 		//Make a local buffer for the header
-		unsigned char* locBuff = new unsigned char[OggPageHeader::OGG_BASE_HEADER_SIZE];
+		unsigned char* locBuff = new unsigned char[OggPageHeader::OGG_BASE_HEADER_SIZE];		//deleted before this function returns
 		
 		//debugLog<<"ProcessBaseHeader : Reading from stream..."<<endl;
 		
@@ -183,8 +186,9 @@
 			locNumRead = locNumRead;
 		}
 
-		bool locRetVal = pendingPage->header()->setBaseHeader((unsigned char*)locBuff);
+		bool locRetVal = pendingPage->header()->setBaseHeader((unsigned char*)locBuff);		//Views pointer only.
 		if (locRetVal == false) {
+			delete[] locBuff;
 			return PROCESS_FAILED_TO_SET_HEADER;
 		}
 	
@@ -195,7 +199,7 @@
 		//Change the state.
 		mState = AWAITING_SEG_TABLE;
 
-
+		delete[] locBuff;
 		//debugLog<<"Bytes needed for seg table = "<<mNumBytesNeeded<<endl;	
 		return PROCESS_OK;
 }
@@ -214,7 +218,7 @@
 	//debugLog<<"Num segments = "<<(int)locNumSegs<<endl;
 
 	//Make a local buffer the size of the segment table. 0 - 255
-	unsigned char* locBuff = new unsigned char[locNumSegs];
+	unsigned char* locBuff = new unsigned char[locNumSegs];				//Given to setSegmentTable. Not deleted here.
 	
 	////debugLog<<"ProcessSegTable : Reading from buffer..."<<endl;
 
@@ -230,7 +234,7 @@
 
 
 	//Make a new segment table from the bufferd data.
-	pendingPage->header()->setSegmentTable(locBuff);
+	pendingPage->header()->setSegmentTable(locBuff);			//This function accepts responsibility for the pointer.
 	locBuff = NULL;
 
 	
@@ -255,11 +259,11 @@
 	unsigned long locPageDataSize = pendingPage->header()->dataSize();
 	
 	//debugLog<<"ProcessDataSegment : Page data size = "<<locPageDataSize<<endl;
-	unsigned char* locBuff = NULL;// = new unsigned char[locPageDataSize];
+	unsigned char* locBuff = NULL;
 	//unsigned long locPacketOffset = 0;
 
 	//THis is a raw pointer into the segment table, don't delete it.
-	unsigned char* locSegTable = pendingPage->header()->SegmentTable();
+	unsigned char* locSegTable = pendingPage->header()->SegmentTable();			//View only don't delete.
 	unsigned int locNumSegs = pendingPage->header()->NumPageSegments();
 	
 	//debugLog<<"ProcessDataSegment : Num segs = "<<locNumSegs<<endl;
@@ -292,7 +296,7 @@
 			//If its the last lacing value or the the lacing value is not 255 (ie packet boundry)
 			
 			//This pointer is given to the packet... it deletes it.
-			locBuff = new unsigned char[locCurrPackSize];
+			locBuff = new unsigned char[locCurrPackSize];				//Given away to constructor of StampedOggPacket.
 
 			//STREAM ACCESS:::
 			//Read data from the stream into the local buffer.
@@ -322,9 +326,10 @@
 					locIsContinuation = true;
 				}
 			}
-
+			//locBuff is given to the constructor of Stamped Ogg Packet... it deletes it.
+			//The new StampedPacket is given to the page... it deletes it
 			pendingPage->addPacket( new StampedOggPacket(locBuff, locCurrPackSize, (locSegTable[i] == 255), locIsContinuation, locPrevGranPos, pendingPage->header()->GranulePos(), StampedOggPacket::OGG_BOTH ) );
-			
+			locBuff = NULL;				//We've given this away.
 			//Reset the packet size counter.
 			locCurrPackSize = 0;
 		}
@@ -337,7 +342,7 @@
 	//debugLog<<"ProcessDataSegment : num bytes needed = "<<mNumBytesNeeded<<endl;
 
 	//Dispatch the finished pagbve
-	eDispatchResult locRet = dispatch(pendingPage);
+	eDispatchResult locRet = dispatch(pendingPage);			//The dispatch function takes responsibility for this page.
 	pendingPage = NULL;   //We give away the pointer
 	
 	if (locRet == DISPATCH_OK) {

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h	2004-10-17 11:21:14 UTC (rev 8039)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h	2004-10-17 15:48:13 UTC (rev 8040)
@@ -127,4 +127,7 @@
 	//DEBUG
 	//fstream debugLog;
 	//
+private:
+	OggDataBuffer& operator=(const OggDataBuffer& other);  /* Don't assign me */
+	OggDataBuffer(const OggDataBuffer& other); /* Don't copy me */
 };

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.cpp	2004-10-17 11:21:14 UTC (rev 8039)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPage.cpp	2004-10-17 15:48:13 UTC (rev 8040)
@@ -34,7 +34,7 @@
 
 OggPage::OggPage(void)
 {
-	mHeader = new OggPageHeader;
+	mHeader = new OggPageHeader;			//Deleted in destructor.
 	
 	
 }

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp	2004-10-17 11:21:14 UTC (rev 8039)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp	2004-10-17 15:48:13 UTC (rev 8040)
@@ -94,7 +94,7 @@
 	setDataSize(retDataSize);
 	return retDataSize;
 }
-
+//Views pointer data only
 bool OggPageHeader::setBaseHeader(const unsigned char* inBaseHeader) {
 	//This now does not delete the buffer
 	
@@ -138,9 +138,7 @@
 
 		mPageState = BASE_HEAD_SET;
 
-		//We are passed our own copy of this so we can delete it now.
-		//delete inBaseHeader;
-		
+				
 		return true;
 	} else {
 		return false;
@@ -242,7 +240,7 @@
 		mNumPageSegments = inVal;
 	}
 }
-
+//Copies the data from the pointer it is given.
 void OggPageHeader::setSegmentTable(const unsigned char* inPtr, unsigned char inNumSegs) {
 	unsigned char* locSegTable = new unsigned char[inNumSegs];
 	memcpy((void*)locSegTable, (const void*)inPtr, inNumSegs);

Modified: trunk/oggdsf/src/tools/iTranscode/iTranscode.cpp
===================================================================
--- trunk/oggdsf/src/tools/iTranscode/iTranscode.cpp	2004-10-17 11:21:14 UTC (rev 8039)
+++ trunk/oggdsf/src/tools/iTranscode/iTranscode.cpp	2004-10-17 15:48:13 UTC (rev 8040)
@@ -163,6 +163,7 @@
 					if ((locFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
 						locNumFound++;
 						cout<<"Found "<<locNumFound << " : "<< locFindData.cFileName<<endl;;
+						bool locTransOK = transcodeToVorbis(locFileName);
 					}
 				}
 	



More information about the commits mailing list