<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head><body ><div style='font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif;'><div><br></div><div><br></div><div><div>Hello,<br></div><div><br></div><div>I am trying to mux audio and video streams to a webm file using libavformat. For video stream, when I call <span class="highlight" style="background-color:rgb(240, 247, 255)"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Consolas, "Lucida Console", monospace"><span class="size" style="font-size:12.8px">av_interleaved_write_frame(), write_packet()</span></span></span></span><br></div><div>is called, which calls <span class="highlight" style="background-color:rgb(240, 247, 255)"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Consolas, "Lucida Console", monospace"><span class="size" style="font-size:12.8px">mkv_write_flush_packet()</span></span></span></span>  in matroskaenc.c. <br></div><div><br></div><div>In that method, <span class="s1">av_packet_unref(&<span class="highlight" style="background-color:rgb(240, 247, 255)"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Consolas, "Lucida Console", monospace"><span class="size" style="font-size:12.8px">MatroskaMuxContext.cur_audio_pkt) </span></span></span></span></span>is called. <span class="s1"><span class="highlight" style="background-color:rgb(240, 247, 255)"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Consolas, "Lucida Console", monospace"><span class="size" style="font-size:12.8px"><span class="highlight" style="background-color:rgb(240, 247, 255)"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Consolas, "Lucida Console", monospace"><span class="size" style="font-size:12.8px">MatroskaMuxContext.cur_audio_pkt </span></span></span></span></span></span></span></span></span>is basically a cached audio packet. If we have a cached audio packet we are writing it with <span class="s1">mkv_write_packet_internal(). And after that we are calling av_packet_unref() to free that packet. But, in that method it is throwing the following error for AVPacket->AVBufferRef->AVBuffer->data, when it is freed.</span><br></div><div><br></div><div><span class="s1"><span class="highlight" style="background-color:rgb(240, 247, 255)"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Consolas, "Lucida Console", monospace"><span class="size" style="font-size:12.8px">"malloc: *** error for object 0x7fda5f816200: pointer being freed was not allocated"</span></span></span></span></span><br></div><div><br></div><div><span class="s1">I am not freeing any modules prior to this. I have debugged it so far using lldb tool to analyze core dump. I am unable to find the exact cause for this. Am I missing something uninitialized or am I passing some argument wrong? Please help me out. </span><br></div><div><br></div><div>P.S:<br></div><div><br></div><div><span class="s1">I am attaching my three C source files here. In that, test.c contains 4 methods, </span><br></div><div><br></div><div><span class="s1">initLibrary() - to initialize library</span><br></div><div><span class="s1">writeVideo()</span><br></div><div><span class="s1">writeAudio()</span><br></div><div><span class="s1">closeFile()</span><br></div><div><br></div><div><span class="s1">which i call accordingly to write audio and video frames to the webm file. And these methods call methods from writewebm.c file.</span><br></div><div><span class="s1">writewebm.c contains actual FFMpeg library calls. So, this error occurs when I call writeVideo() with AVPacket containing a video frame. But it is not  consistent though. </span><br></div><div><span class="s1">And, the same issue also  occurs when in order to close the file I call av_write_trailer(), where it checks for all cached audio packets and tries to write them to the file.</span><br></div><div><br></div><div><br></div></div><div><div>Thanks.<br></div><div>Ravi Kiran B S<br></div><div><br></div><div><br></div></div><div><br></div></div><br></body></html>