[FFmpeg-devel] [PATCH 2/3] avformat/rtspdec: fix mem leaks on init fail

Andriy Gelman andriy.gelman at gmail.com
Mon Oct 12 06:53:51 EEST 2020


On Sun, 11. Oct 22:04, Andriy Gelman wrote:
> On Sun, 11. Oct 22:44, Andreas Rheinhardt wrote:
> > Andriy Gelman:
> > > From: Andriy Gelman <andriy.gelman at gmail.com>
> > > 
> > > Fixes #6334
> > > 
> > > Signed-off-by: Andriy Gelman <andriy.gelman at gmail.com>
> > > ---
> > >  libavformat/rtspdec.c | 17 ++++++++++-------
> > >  1 file changed, 10 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
> > > index b519b6f1a2..623f478585 100644
> > > --- a/libavformat/rtspdec.c
> > > +++ b/libavformat/rtspdec.c
> > > @@ -720,7 +720,7 @@ static int rtsp_read_header(AVFormatContext *s)
> > >      if (rt->rtsp_flags & RTSP_FLAG_LISTEN) {
> > >          ret = rtsp_listen(s);
> > >          if (ret)
> > > -            return ret;
> > > +            goto fail;
> 
> > 
> > This will add one ff_network_close() to this codepath. Is it really
> > certain that there was a corresponding ff_network_init()? 
> > (And where is
> > the ff_network_init() that is cancelled in rtsp_read_close() anyway?)
> 
> Besides my patch, there is an extra ff_network_init() in ff_rtsp_connect(),
> which is missing from rtsp_listen().
> 
> This means there'll be an extra ff_network_close() call in listen mode (when the
> stream exits without errors). 
> 

> I think the best solution is to remove ff_network_init() from ff_rtsp_connect()
> and then remove ff_network_close() from rtsp_read_close() and the fail path of
> ff_rtsp_connect().   
> 
> Calling ff_network_init() separately in ff_rtsp_connect() seems redundant
> because the function is called in each url_alloc_for_protocol() anyway.. and it
> only complicates the cleanup after init failure. 
> 

Seems ff_url_join() which is called before url_alloc_for_protocol() needs to
ensure ff_network_init() has been called. The above approach will not work then. 

-- 
Andriy


More information about the ffmpeg-devel mailing list