OutputContainer.mux_one leaks memory
If I mux 100 packets to a stream, valgrind reports memory loss.
The simple program I use:
import av
container = av.open('foo.mp4', 'w')
stream = container.add_stream('mpeg4')
for i in range(100):
frame = av.VideoFrame(640, 480)
for packet in stream.encode(frame):
container.mux(packet)
for packet in stream.encode(None):
container.mux(packet)
Valgrind output:
==1809== 8,800 bytes in 100 blocks are definitely lost in loss record 528 of 546
==1809== at 0x4837B26: memalign (vg_replace_malloc.c:857)
==1809== by 0x4837C41: posix_memalign (vg_replace_malloc.c:1020)
==1809== by 0x570228A: av_malloc (in /usr/lib/x86_64-linux-gnu/libavutil.so.56.14.100)
==1809== by 0x570261C: av_mallocz (in /usr/lib/x86_64-linux-gnu/libavutil.so.56.14.100)
==1809== by 0x59044FE: av_packet_alloc (in /usr/lib/x86_64-linux-gnu/libavcodec.so.58.18.100)
==1809== by 0x5904CCC: av_packet_clone (in /usr/lib/x86_64-linux-gnu/libavcodec.so.58.18.100)
==1809== by 0x1C245998: __pyx_pf_2av_9container_6output_15OutputContainer_12mux_one (output.c:4882)
==1809== by 0x1C2456CB: __pyx_pw_2av_9container_6output_15OutputContainer_13mux_one (output.c:4782)
==1809== by 0x1C2489A5: __Pyx_PyObject_CallMethO (output.c:5969)
==1809== by 0x1C248C96: __Pyx_PyObject_CallOneArg (output.c:6044)
==1809== by 0x1C2446C7: __pyx_pf_2av_9container_6output_15OutputContainer_10mux (output.c:4580)
==1809== by 0x1C244504: __pyx_pw_2av_9container_6output_15OutputContainer_11mux (output.c:4527)
The loss grows with every packet I mux. I wonder if we have understood packet reference counting correctly.