Fixed memory leak in FLV library.
This commit is contained in:
parent
014aa97770
commit
7565b705ad
2 changed files with 18 additions and 6 deletions
|
@ -335,6 +335,16 @@ FLV::Tag::Tag(const RTMPStream::Chunk& O){
|
||||||
ChunkLoader(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.
|
/// Assignment operator - works exactly like the copy constructor.
|
||||||
/// This operator checks for self-assignment.
|
/// This operator checks for self-assignment.
|
||||||
FLV::Tag & FLV::Tag::operator=(const FLV::Tag& O){
|
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){
|
bool FLV::Tag::ChunkLoader(const RTMPStream::Chunk& O){
|
||||||
len = O.len + 15;
|
len = O.len + 15;
|
||||||
if (len > 0){
|
if (len > 0){
|
||||||
if ( !data){
|
if (buf < len || !data){
|
||||||
data = (char*)malloc(len);
|
char * newdata = (char*)realloc(data, len);
|
||||||
buf = len;
|
// on realloc fail, retain the old data
|
||||||
}else{
|
if (newdata != 0){
|
||||||
if (buf < len){
|
data = newdata;
|
||||||
data = (char*)realloc(data, len);
|
|
||||||
buf = len;
|
buf = len;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(data + 11, &(O.data[0]), O.len);
|
memcpy(data + 11, &(O.data[0]), O.len);
|
||||||
|
|
|
@ -39,6 +39,7 @@ namespace FLV {
|
||||||
Tag(const Tag& O); ///< Copy constructor, copies the contents of an existing tag.
|
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 & operator=(const Tag& O); ///< Assignment operator - works exactly like the copy constructor.
|
||||||
Tag(const RTMPStream::Chunk& O); ///<Copy constructor from a RTMP chunk.
|
Tag(const RTMPStream::Chunk& O); ///<Copy constructor from a RTMP chunk.
|
||||||
|
~Tag(); ///< Generic destructor.
|
||||||
//loader functions
|
//loader functions
|
||||||
bool ChunkLoader(const RTMPStream::Chunk& O);
|
bool ChunkLoader(const RTMPStream::Chunk& O);
|
||||||
bool DTSCLoader(DTSC::Stream & S);
|
bool DTSCLoader(DTSC::Stream & S);
|
||||||
|
|
Loading…
Add table
Reference in a new issue