[FFmpeg-devel] [PATCH 1/2] lavc/qsvenc: Fix the memory leak for enc_ctrl.Payload
Fu, Linjie
linjie.fu at intel.com
Thu Apr 11 09:52:59 EEST 2019
> -----Original Message-----
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces at ffmpeg.org] On Behalf
> Of Carl Eugen Hoyos
> Sent: Wednesday, April 10, 2019 19:35
> To: FFmpeg development discussions and patches <ffmpeg-
> devel at ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 1/2] lavc/qsvenc: Fix the memory leak
> for enc_ctrl.Payload
>
> 2019-04-10 13:27 GMT+02:00, Linjie Fu <linjie.fu at intel.com>:
> > 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.
> >
> > Fix the memory leak issue and reset other members in mfxEncodeCtrl.
> >
> > Signed-off-by: Linjie Fu <linjie.fu at intel.com>
> > ---
> > libavcodec/qsvenc.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index 5aa020d47b..029bb562d6 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -1254,7 +1254,7 @@ 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));
> > + memset(enc_ctrl, 0, sizeof(mfxEncodeCtrl) - sizeof(mfxPayload **));
>
> Am I correct that this assumes a particular order of
> contents in a struct not defined within FFmpeg?
> Maybe saving the pointer in a variable and writing
> it back is more future proof?
>
Yes it's a structure defined in MediaSDK, and will move the memset to the
start of the allocation to avoid this.
Thanks,
Linjie
More information about the ffmpeg-devel
mailing list