[xiph-commits] r8041 - trunk/oggdsf/src/lib/core/ogg/libOOOgg

illiminable at motherfish-iii.xiph.org illiminable at motherfish-iii.xiph.org
Sun Oct 17 09:07:29 PDT 2004


Author: illiminable
Date: 2004-10-17 09:07:28 -0700 (Sun, 17 Oct 2004)
New Revision: 8041

Modified:
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacket.cpp
   trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacket.h
Log:
* OggPacket leak free.
* Missed some required virtual destructors.

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h	2004-10-17 15:48:13 UTC (rev 8040)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h	2004-10-17 16:07:28 UTC (rev 8041)
@@ -98,7 +98,7 @@
 {
 public:
 	CircularBuffer(unsigned long inBufferSize);
-	~CircularBuffer(void);
+	virtual ~CircularBuffer(void);
 
 	//IFIFOBuffer Implementation
 	virtual unsigned long read(unsigned char* outData, unsigned long inBytesToRead);

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h	2004-10-17 15:48:13 UTC (rev 8040)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h	2004-10-17 16:07:28 UTC (rev 8041)
@@ -87,7 +87,7 @@
 
 	//Constructors
 	OggDataBuffer(void);
-	~OggDataBuffer(void);
+	virtual ~OggDataBuffer(void);
 
 	//Setting callbacks
 	bool registerStaticCallback(fPageCallback inPageCallback);

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacket.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacket.cpp	2004-10-17 15:48:13 UTC (rev 8040)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacket.cpp	2004-10-17 16:07:28 UTC (rev 8041)
@@ -32,6 +32,7 @@
 #include "StdAfx.h"
 #include "oggpacket.h"
 
+//LEAK CHECK::: 20041018 - OK.
 OggPacket::OggPacket(void)
 	:	mPacketSize(0)
 	,	mPacketData(NULL)
@@ -42,6 +43,7 @@
 
 }
 
+//Accepts responsibility for inPackData pointer - deletes it in destructor.
 OggPacket::OggPacket(unsigned char* inPackData, unsigned long inPacketSize, bool inIsTruncated, bool inIsContinuation)
 	:	mPacketSize(inPacketSize)
 	,	mPacketData(inPackData)
@@ -50,15 +52,17 @@
 		
 {
 }
+
+//This method creates a pointer which the caller is responsible for.
 OggPacket* OggPacket::clone() {
 	//Make a new buffer for packet data
-	unsigned char* locBuff = new unsigned char[mPacketSize];
+	unsigned char* locBuff = new unsigned char[mPacketSize];			//Given to constructor of OggPacket
 
 	//Copy the packet data into the new buffer
 	memcpy((void*)locBuff, (const void*)mPacketData, mPacketSize);
 
-	//Create the new packet
-	OggPacket* retPack = new OggPacket(locBuff, mPacketSize, mIsTruncated, mIsContinuation);
+	//Create the new packet - accepts locBuff poitner
+	OggPacket* retPack = new OggPacket(locBuff, mPacketSize, mIsTruncated, mIsContinuation);	//Gives this pointer to the caller.
 	return retPack;
 }
 
@@ -189,14 +193,15 @@
 	mPacketSize = inPacketSize;
 }
 
+//This function accepts responsibility for the pointer it is passed, and it deletes it in the destructor.
 void OggPacket::setPacketData(unsigned char* inPacketData) {
 	mPacketData = inPacketData;
 }
 
-
-void OggPacket::merge(OggPacket* inMorePacket) {
+//Only views the incoming pointer.
+void OggPacket::merge(const OggPacket* inMorePacket) {
 	//Make a new buffer the size of both data segs together
-	unsigned char* locBuff = new unsigned char[mPacketSize + inMorePacket->mPacketSize];
+	unsigned char* locBuff = new unsigned char[mPacketSize + inMorePacket->mPacketSize];		//This is put into the member vvariable, where it will be deleted in destructor.
 	//Copy this packets data to the start
 	memcpy((void*)locBuff, (const void*)mPacketData, mPacketSize);
 	//Copy the next packets data after it
@@ -211,7 +216,7 @@
 	//If the next part of the packet isn't complete then this packet is not complete.
 	//mIsComplete = inMorePacket->mIsComplete;
 	//The new packet is truncated only if the incoming packet is
-	mIsTruncated = inMorePacket->isTruncated();
+	mIsTruncated = inMorePacket->mIsTruncated;    //->isTruncated();
 
 	//This is not a continuation... a continuation is a packet that does not start at the start of the real packet.
 	mIsContinuation = false;

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacket.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacket.h	2004-10-17 15:48:13 UTC (rev 8040)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPacket.h	2004-10-17 16:07:28 UTC (rev 8041)
@@ -62,7 +62,7 @@
 	void setPacketData (unsigned char* inPacketData );
 
 	//Merge function
-	virtual void merge(OggPacket* inMorePacket);
+	virtual void merge(const OggPacket* inMorePacket);
 
 	//TODO::: Should this be here ?
 	string toPackDumpString();
@@ -78,5 +78,9 @@
 	//TODO::Should these be here ?
 	string OggPacket::dumpNCharsToString(unsigned char* inStartPoint, unsigned long inNumChars) ;
 	string OggPacket::padField(string inString, unsigned long inPadWidth, unsigned char inPadChar);
+
+private:
+	OggPacket& operator=(const OggPacket& other);  /* Don't assign me */
+	OggPacket(const OggPacket& other); /* Don't copy me */
 	
 };



More information about the commits mailing list