Skip to content

Commit a92879d

Browse files
author
Clement Champetier
committed
IFrame: fix memory leak when calling assignValue
* The data buffer of the frame should be freed before allocate a new buffer. * The new buffer should be allocated using malloc instead of free, since ffmpeg/libav uses free to deallocate the data. The valgrind error was: "Mismatched free() / delete / delete []".
1 parent 2a61683 commit a92879d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/AvTranscoder/data/decoded/IFrame.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,19 @@ void IFrame::freeAVFrame()
6464

6565
void IFrame::assignValue(const unsigned char value)
6666
{
67+
// Free the existing data
68+
freeData();
69+
6770
// Create the buffer
6871
const int bufferSize = getSize();
69-
unsigned char* dataBuffer = new unsigned char[bufferSize];
72+
unsigned char* dataBuffer = static_cast<unsigned char*>(malloc(bufferSize * sizeof(unsigned char)));
7073
memset(dataBuffer, value, bufferSize);
7174

7275
// Fill the frame
7376
assignBuffer(dataBuffer);
77+
78+
// Prepare to free the data
79+
_dataAllocated = true;
7480
}
7581

7682
bool IFrame::isAudioFrame() const

0 commit comments

Comments
 (0)