GNOME Bugzilla – Bug 726814
avvidenc: Fix leak of AVBufferRef
Last modified: 2014-04-29 07:14:26 UTC
Attached is a patch to fix the following leak (using avenc_h263p): ==24185== 64 (24 direct, 40 indirect) bytes in 1 blocks are definitely lost in loss record 2,201 of 3,197 ==24185== at 0x4C2C930: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==24185== by 0x4C2CA57: posix_memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==24185== by 0x942C5AD: av_malloc (mem.c:81) ==24185== by 0x942C6FD: av_mallocz (mem.c:207) ==24185== by 0x9426143: av_buffer_create (buffer.c:47) ==24185== by 0x9426483: av_buffer_realloc (buffer.c:158) ==24185== by 0x9315219: av_new_packet (avpacket.c:71) ==24185== by 0x9331A7E: ff_MPV_encode_picture (mpegvideo_enc.c:1501) ==24185== by 0x933FBCC: avcodec_encode_video2 (utils.c:1314) ==24185== by 0x92E5817: gst_ffmpegvidenc_handle_frame (gstavvidenc.c:584) ==24185== by 0x579C690: gst_video_encoder_chain (gstvideoencoder.c:1433) ==24185== by 0x5A3C895: gst_pad_chain_data_unchecked (gstpad.c:3809) ==24185== by 0x5A3D547: gst_pad_push_data (gstpad.c:4042) ...
I guess you forgot to attach the patch.
Created attachment 272559 [details] [review] Patch to fix the leak
*** Bug 729165 has been marked as a duplicate of this bug. ***
Review of attachment 272559 [details] [review]: Looks good in general but ::: ext/libav/gstavvidenc.c @@ +596,3 @@ + if (ret < 0 || !have_data) + g_slice_free (AVPacket, pkt); Shouldn't this call gst_ffmpegvidenc_free_avpacket() too, i.e. also av_packet_unref()?
Before returning from avcodec_encode_video2() there is the following code: if (ret < 0 || !*got_packet_ptr) av_free_packet(avpkt); which is logically the same as that test in the element. We should not call av_packet_unref() after this and it looks like the memory is freed correctly. I agree it's slightly confusing to assume such behavior, but should be OK since it's also described in the documentation of avcodec_encode_video2().
commit 6d92f18d1b3ea9dd40a4feb0f953e938895a8a83 Author: Sebastian Dröge <sebastian@centricular.com> Date: Tue Apr 29 09:13:44 2014 +0200 avaudenc: Fix leak of AVBufferRef AVPacket contains AVBufferRef which may leak unless unreffed properly. https://bugzilla.gnome.org/show_bug.cgi?id=726814 commit 245be5651003110fb954766cd74de1630fbed288 Author: Stian Selnes <stian@pexip.com> Date: Fri Mar 21 10:10:14 2014 +0100 avvidenc: Fix leak of AVBufferRef AVPacket contains AVBufferRef which may leak unless unreffed properly. https://bugzilla.gnome.org/show_bug.cgi?id=726814