[FFmpeg-devel] [PATCH 2/2] ffserver: fix streams memleak when closing a connection.

Clément Bœsch ubitux at gmail.com
Thu Nov 15 09:42:21 CET 2012


On Wed, Nov 14, 2012 at 05:18:45PM +0100, Michael Niedermayer wrote:
> On Tue, Nov 13, 2012 at 04:35:18PM +0100, Clément Bœsch wrote:
> > From: Clément Bœsch <clement.boesch at smartjog.com>
> > 
> > ---
> >  ffserver.c |    1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/ffserver.c b/ffserver.c
> > index 0d2a8a7..28a614f 100644
> > --- a/ffserver.c
> > +++ b/ffserver.c
> > @@ -929,6 +929,7 @@ static void close_connection(HTTPContext *c)
> >  
> >      for(i=0; i<ctx->nb_streams; i++)
> >          av_free(ctx->streams[i]);
> > +    av_free(ctx->streams);
> 
> should be av_freep()
> 

Well, a few lines below the whole context is completely destroyed so it
doesn't really matter, but changed anyway since it doesn't hurt either.

Also note that this isn't enough to fix the leak: adding a
av_free(ctx->priv_data) fixes the real problem. Both streams and priv_data
are locally allocated, the rest of the structure is shared between the
connections so we can't use avformat_free_context() or similar.

New patch attached.

-- 
Clément B.
-------------- next part --------------
From 93df34bcc708ab17fcd2da231e63ac51bdb2c1b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <clement.boesch at smartjog.com>
Date: Tue, 13 Nov 2012 17:32:35 +0200
Subject: [PATCH] ffserver: fix streams and priv_data memleaks when closing a
 connection.

---
 ffserver.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/ffserver.c b/ffserver.c
index 18271ce..1f27237 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -929,6 +929,8 @@ static void close_connection(HTTPContext *c)
 
     for(i=0; i<ctx->nb_streams; i++)
         av_free(ctx->streams[i]);
+    av_freep(&ctx->streams);
+    av_freep(&ctx->priv_data);
 
     if (c->stream && !c->post && c->stream->stream_type == STREAM_TYPE_LIVE)
         current_bandwidth -= c->stream->bandwidth;
-- 
1.7.10.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121115/fd3d5aad/attachment.asc>


More information about the ffmpeg-devel mailing list