Fixed memory leak in FLV library.

This commit is contained in:
Thulinma 2013-04-05 16:36:29 +02:00
parent 014aa97770
commit 7565b705ad
2 changed files with 18 additions and 6 deletions

View file

@ -335,6 +335,16 @@ FLV::Tag::Tag(const RTMPStream::Chunk& O){
ChunkLoader(O);
}
/// Generic destructor that frees the allocated memory in the internal data variable, if any.
FLV::Tag::~Tag(){
if (data){
free(data);
data = 0;
buf = 0;
len = 0;
}
}
/// Assignment operator - works exactly like the copy constructor.
/// This operator checks for self-assignment.
FLV::Tag & FLV::Tag::operator=(const FLV::Tag& O){
@ -759,13 +769,14 @@ bool FLV::Tag::DTSCMetaInit(DTSC::Stream & S){
bool FLV::Tag::ChunkLoader(const RTMPStream::Chunk& O){
len = O.len + 15;
if (len > 0){
if ( !data){
data = (char*)malloc(len);
buf = len;
}else{
if (buf < len){
data = (char*)realloc(data, len);
if (buf < len || !data){
char * newdata = (char*)realloc(data, len);
// on realloc fail, retain the old data
if (newdata != 0){
data = newdata;
buf = len;
}else{
return false;
}
}
memcpy(data + 11, &(O.data[0]), O.len);

View file

@ -39,6 +39,7 @@ namespace FLV {
Tag(const Tag& O); ///< Copy constructor, copies the contents of an existing tag.
Tag & operator=(const Tag& O); ///< Assignment operator - works exactly like the copy constructor.
Tag(const RTMPStream::Chunk& O); ///<Copy constructor from a RTMP chunk.
~Tag(); ///< Generic destructor.
//loader functions
bool ChunkLoader(const RTMPStream::Chunk& O);
bool DTSCLoader(DTSC::Stream & S);