[FFmpeg-devel] Memory leak using bitstream filters with shared libs

Michael Niedermayer michaelni
Sun Mar 9 23:00:54 CET 2008


On Sun, Mar 09, 2008 at 07:50:16PM +0100, Reimar D?ffinger wrote:
> On Sun, Mar 09, 2008 at 12:05:33AM +0000, M?ns Rullg?rd wrote:
> > Baptiste discovered a rather nasty memory leak when using a bitstream
> > filter with shared libraries.
> > 
> > In ffmpeg.c:write_frame() the output of bitstream filters is stored in
> > an AVPacket, and its destruct function is set like this (line 417):
> > 
> >             new_pkt.destruct= av_destruct_packet;
> > 
> > Later on, in av_interleave_packet_per_dts(), AVPacket.destruct is
> > compared against av_destruct_packet, like this (utils.c:2439):
> > 
> >         if(pkt->destruct == av_destruct_packet)
> 
> This seems like a misuse of pkt->destruct to me anyway, and for a simple
> optimization in addition.
> I am still not entirely certain I understood what this does, but I think
> that a pkt->flag PKT_FREE_ON_DESTRUCT or some such would do.

ugh ....
No it would not do. It completely defeats the sense behind destruct() that
is to allow a destruct different from what av_free() does.
One solution i could see is to:
 static inline void av_free_packet(AVPacket *pkt)
 {
-    if (pkt && pkt->destruct) {
-        pkt->destruct(pkt);
+    if(pkt){
+        if(pkt->destruct)
+            pkt->destruct(pkt);
+        pkt->data = NULL; pkt->size = 0;
     }
 }
----
 void av_destruct_packet(AVPacket *pkt)
 {
     av_free(pkt->data);
-    pkt->data = NULL; pkt->size = 0;
 }
----
-void av_destruct_packet_nofree(AVPacket *pkt)
-{
-    pkt->data = NULL; pkt->size = 0;
-}

and use NULL instead of av_destruct_packet_nofree

Anyway ive no interrest to workaround binutil bugs, if anyone cares he has
to do the work and testing.

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No great genius has ever existed without some touch of madness. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080309/0317220b/attachment.pgp>



More information about the ffmpeg-devel mailing list