How to new & delete AVPacket?
av_new_packet
creates a packet and allocates dataav_init_packet
sets all packet members to default, and sets data pointer toNULL
, the leak is hereav_free_packet
clears all visible members, but your data is already leaking
If you want FFmpeg to allocate the data for you, do not call av_init_packet
. If you want to handle the data yourself, allocate the packet object on the stack and set its data yourself (and free it yourself):
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = dataBuffer;
pkt.size = dataBufferSize;
// use your packet
// free your dataBuffer