[matroska] r958 - in trunk/libmatroska: matroska src

[email protected]
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: mosu
Date: 2004-11-30 18:45:16 +0300 (Tue, 30 Nov 2004)
New Revision: 958

Modified:
   trunk/libmatroska/matroska/KaxBlock.h
   trunk/libmatroska/src/KaxBlock.cpp
Log:
Use malloc() and free() instead of new[] and delete[] where the lib might deal with pointers that have been allocated by the app, or where the app has allocated the memory. Reason: new[]ed memory cannot be realloc()ed.

Modified: trunk/libmatroska/matroska/KaxBlock.h
===================================================================
--- trunk/libmatroska/matroska/KaxBlock.h	2004-11-30 15:41:57 UTC (rev 957)
+++ trunk/libmatroska/matroska/KaxBlock.h	2004-11-30 15:45:16 UTC (rev 958)
@@ -80,9 +80,6 @@
 		virtual DataBuffer * Clone();
 };
 
-/*!
-	\warning the binary buffer should be allocated with the new binary* operator : "new binary[your_size]"
-*/
 class MATROSKA_DLL_API SimpleDataBuffer : public DataBuffer {
 	public:
 		SimpleDataBuffer(binary * aBuffer, uint32 aSize, uint32 aOffset, bool (*aFreeBuffer)(const DataBuffer & aBuffer) = myFreeBuffer)
@@ -99,7 +96,9 @@
 
 		static bool myFreeBuffer(const DataBuffer & aBuffer)
 		{
-			delete[] static_cast<const SimpleDataBuffer*>(&aBuffer)->BaseBuffer;
+			binary *_Buffer = static_cast<const SimpleDataBuffer*>(&aBuffer)->BaseBuffer;
+			if (_Buffer != NULL)
+				free(_Buffer);
 			return true;
 		}
 

Modified: trunk/libmatroska/src/KaxBlock.cpp
===================================================================
--- trunk/libmatroska/src/KaxBlock.cpp	2004-11-30 15:41:57 UTC (rev 957)
+++ trunk/libmatroska/src/KaxBlock.cpp	2004-11-30 15:45:16 UTC (rev 958)
@@ -110,7 +110,8 @@
 
 DataBuffer * DataBuffer::Clone()
 {
-	binary *ClonedData = new binary[mySize];
+	binary *ClonedData = (binary *)malloc(mySize * sizeof(binary));
+	assert(ClonedData != NULL);
 	memcpy(ClonedData, myBuffer ,mySize );
 
 	SimpleDataBuffer * result = new SimpleDataBuffer(ClonedData, mySize, 0);
@@ -119,8 +120,9 @@
 }
 
 SimpleDataBuffer::SimpleDataBuffer(const SimpleDataBuffer & ToClone)
- :DataBuffer(new binary[ToClone.mySize], ToClone.mySize, myFreeBuffer)
+ :DataBuffer((binary *)malloc(ToClone.mySize * sizeof(binary)), ToClone.mySize, myFreeBuffer)
 {
+	assert(myBuffer != NULL);
 	memcpy(myBuffer, ToClone.myBuffer ,mySize );
 	bValidValue = ToClone.bValidValue;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.