diff mbox

[FFmpeg-devel,v2] lavc/qsvenc: Fix the memory leak for enc_ctrl.Payload

Message ID 20190415132318.19975-1-linjie.fu@intel.com
State Accepted
Commit 8f6e65183354d1d402ae80c71cba2759fe152018
Headers show

Commit Message

Fu, Linjie April 15, 2019, 1:23 p.m. UTC
frame->enc_ctrl.Payload is malloced in get_free_frame, directly memset
the whole structure of enc_ctrl to zero will cause the memory leak for
enc_ctrl.Payload.

frame->enc_ctrl as a structure will be malloc and init to zero by calling
frame = av_mallocz(sizeof(*frame)), so the memset is redundant and can
be removed.

Can be reproduced by #7830.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
 libavcodec/qsvenc.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Zhong Li April 29, 2019, 9 a.m. UTC | #1
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf

> Of Linjie Fu

> Sent: Monday, April 15, 2019 9:23 PM

> To: ffmpeg-devel@ffmpeg.org

> Cc: Fu, Linjie <linjie.fu@intel.com>

> Subject: [FFmpeg-devel] [PATCH, v2] lavc/qsvenc: Fix the memory leak for

> enc_ctrl.Payload

> 

> frame->enc_ctrl.Payload is malloced in get_free_frame, directly memset

> the whole structure of enc_ctrl to zero will cause the memory leak for

> enc_ctrl.Payload.

> 

> frame->enc_ctrl as a structure will be malloc and init to zero by

> frame->calling

> frame = av_mallocz(sizeof(*frame)), so the memset is redundant and can be

> removed.

> 

> Can be reproduced by #7830.


Patch LGTM now, but I can't see strong relationship between this patch and tikect #7830.
IMHO this is a quite common issue even if you use qsv transcoding pipeline? 

> Signed-off-by: Linjie Fu <linjie.fu@intel.com>

> ---

>  libavcodec/qsvenc.c | 1 -

>  1 file changed, 1 deletion(-)

> 

> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index

> 5aa020d47b..19953bd4ea 100644

> --- a/libavcodec/qsvenc.c

> +++ b/libavcodec/qsvenc.c

> @@ -1254,7 +1254,6 @@ static int encode_frame(AVCodecContext *avctx,

> QSVEncContext *q,

>      if (qsv_frame) {

>          surf = &qsv_frame->surface;

>          enc_ctrl = &qsv_frame->enc_ctrl;

> -        memset(enc_ctrl, 0, sizeof(mfxEncodeCtrl));

> 

>          if (frame->pict_type == AV_PICTURE_TYPE_I) {

>              enc_ctrl->FrameType = MFX_FRAMETYPE_I |

> MFX_FRAMETYPE_REF;

> --

> 2.17.1
Fu, Linjie May 22, 2019, 5:49 a.m. UTC | #2
> -----Original Message-----

> From: Li, Zhong

> Sent: Monday, April 29, 2019 17:00

> To: FFmpeg development discussions and patches <ffmpeg-

> devel@ffmpeg.org>

> Cc: Fu, Linjie <linjie.fu@intel.com>

> Subject: RE: [FFmpeg-devel] [PATCH, v2] lavc/qsvenc: Fix the memory leak

> for enc_ctrl.Payload

> 

> > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On

> Behalf

> > Of Linjie Fu

> > Sent: Monday, April 15, 2019 9:23 PM

> > To: ffmpeg-devel@ffmpeg.org

> > Cc: Fu, Linjie <linjie.fu@intel.com>

> > Subject: [FFmpeg-devel] [PATCH, v2] lavc/qsvenc: Fix the memory leak for

> > enc_ctrl.Payload

> >

> > frame->enc_ctrl.Payload is malloced in get_free_frame, directly memset

> > the whole structure of enc_ctrl to zero will cause the memory leak for

> > enc_ctrl.Payload.

> >

> > frame->enc_ctrl as a structure will be malloc and init to zero by

> > frame->calling

> > frame = av_mallocz(sizeof(*frame)), so the memset is redundant and can

> be

> > removed.

> >

> > Can be reproduced by #7830.

> 

> Patch LGTM now, but I can't see strong relationship between this patch and

> tikect #7830.

> IMHO this is a quite common issue even if you use qsv transcoding pipeline?


Yes, it's not strongly related with the issue. Remove this would be fine.
Thanks.

> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>

> > ---

> >  libavcodec/qsvenc.c | 1 -

> >  1 file changed, 1 deletion(-)

> >

> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index

> > 5aa020d47b..19953bd4ea 100644

> > --- a/libavcodec/qsvenc.c

> > +++ b/libavcodec/qsvenc.c

> > @@ -1254,7 +1254,6 @@ static int encode_frame(AVCodecContext *avctx,

> > QSVEncContext *q,

> >      if (qsv_frame) {

> >          surf = &qsv_frame->surface;

> >          enc_ctrl = &qsv_frame->enc_ctrl;

> > -        memset(enc_ctrl, 0, sizeof(mfxEncodeCtrl));

> >

> >          if (frame->pict_type == AV_PICTURE_TYPE_I) {

> >              enc_ctrl->FrameType = MFX_FRAMETYPE_I |

> > MFX_FRAMETYPE_REF;

> > --

> > 2.17.1
Zhong Li May 22, 2019, 2:21 p.m. UTC | #3
> From: Fu, Linjie

> Sent: Wednesday, May 22, 2019 1:50 PM

> To: Li, Zhong <zhong.li@intel.com>; FFmpeg development discussions and

> patches <ffmpeg-devel@ffmpeg.org>

> Subject: RE: [FFmpeg-devel] [PATCH, v2] lavc/qsvenc: Fix the memory leak

> for enc_ctrl.Payload

> 

> > -----Original Message-----

> > From: Li, Zhong

> > Sent: Monday, April 29, 2019 17:00

> > To: FFmpeg development discussions and patches <ffmpeg-

> > devel@ffmpeg.org>

> > Cc: Fu, Linjie <linjie.fu@intel.com>

> > Subject: RE: [FFmpeg-devel] [PATCH, v2] lavc/qsvenc: Fix the memory

> > leak for enc_ctrl.Payload

> >

> > > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On

> > Behalf

> > > Of Linjie Fu

> > > Sent: Monday, April 15, 2019 9:23 PM

> > > To: ffmpeg-devel@ffmpeg.org

> > > Cc: Fu, Linjie <linjie.fu@intel.com>

> > > Subject: [FFmpeg-devel] [PATCH, v2] lavc/qsvenc: Fix the memory leak

> > > for enc_ctrl.Payload

> > >

> > > frame->enc_ctrl.Payload is malloced in get_free_frame, directly

> > > frame->memset

> > > the whole structure of enc_ctrl to zero will cause the memory leak

> > > for enc_ctrl.Payload.

> > >

> > > frame->enc_ctrl as a structure will be malloc and init to zero by

> > > frame->calling

> > > frame = av_mallocz(sizeof(*frame)), so the memset is redundant and

> > > can

> > be

> > > removed.

> > >

> > > Can be reproduced by #7830.

> >

> > Patch LGTM now, but I can't see strong relationship between this patch

> > and tikect #7830.

> > IMHO this is a quite common issue even if you use qsv transcoding

> pipeline?

> 

> Yes, it's not strongly related with the issue. Remove this would be fine.

> Thanks.


Applied with commit message modified. 
Thanks.
diff mbox

Patch

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 5aa020d47b..19953bd4ea 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1254,7 +1254,6 @@  static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
     if (qsv_frame) {
         surf = &qsv_frame->surface;
         enc_ctrl = &qsv_frame->enc_ctrl;
-        memset(enc_ctrl, 0, sizeof(mfxEncodeCtrl));
 
         if (frame->pict_type == AV_PICTURE_TYPE_I) {
             enc_ctrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;