From 69470edc3e029010cf7530bc48e643e2f64aa79e Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Fri, 10 May 2019 14:06:04 +0800 Subject: [PATCH] Add free logic of picParams->pDeltaQp for avoiding memory leak. Fixes #611. Signed-off-by: Yan Wang --- .../linux/common/codec/ddi/media_ddi_encode_avc.cpp | 11 +++++++++++ .../linux/common/codec/ddi/media_ddi_encode_avc.h | 2 ++ .../linux/common/codec/ddi/media_ddi_encode_base.cpp | 5 +++++ .../linux/common/codec/ddi/media_ddi_encode_base.h | 8 ++++++++ 4 files changed, 26 insertions(+) diff --git a/media_driver/linux/common/codec/ddi/media_ddi_encode_avc.cpp b/media_driver/linux/common/codec/ddi/media_ddi_encode_avc.cpp index 4a3c83a7f0..81af2bceaf 100644 --- a/media_driver/linux/common/codec/ddi/media_ddi_encode_avc.cpp +++ b/media_driver/linux/common/codec/ddi/media_ddi_encode_avc.cpp @@ -2066,3 +2066,14 @@ uint32_t DdiEncodeAvc::getQMatrixBufferSize() { return sizeof(VAIQMatrixBufferH264); } + +void DdiEncodeAvc::ClearPicParams() +{ + uint8_t ppsIdx = ((PCODEC_AVC_ENCODE_SLICE_PARAMS)(m_encodeCtx->pSliceParams))->pic_parameter_set_id; + PCODEC_AVC_ENCODE_PIC_PARAMS picParams = (PCODEC_AVC_ENCODE_PIC_PARAMS)m_encodeCtx->pPicParams + ppsIdx; + + if (picParams != nullptr && picParams->pDeltaQp != nullptr) + { + MOS_FreeMemory(picParams->pDeltaQp); + } +} diff --git a/media_driver/linux/common/codec/ddi/media_ddi_encode_avc.h b/media_driver/linux/common/codec/ddi/media_ddi_encode_avc.h index ba11b936ec..e0deeec635 100644 --- a/media_driver/linux/common/codec/ddi/media_ddi_encode_avc.h +++ b/media_driver/linux/common/codec/ddi/media_ddi_encode_avc.h @@ -180,6 +180,8 @@ class DdiEncodeAvc : public DdiEncodeBase DDI_MEDIA_CONTEXT *mediaCtx, void *ptr); + virtual void ClearPicParams() override; + //! //! \brief Convert slice struct from VA to codechal //! \details Convert slice struct from VA to codechal diff --git a/media_driver/linux/common/codec/ddi/media_ddi_encode_base.cpp b/media_driver/linux/common/codec/ddi/media_ddi_encode_base.cpp index 9aab031066..10875680d4 100644 --- a/media_driver/linux/common/codec/ddi/media_ddi_encode_base.cpp +++ b/media_driver/linux/common/codec/ddi/media_ddi_encode_base.cpp @@ -75,6 +75,7 @@ VAStatus DdiEncodeBase::EndPicture( DDI_CHK_NULL(mediaCtx, "Null mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT); VAStatus status = EncodeInCodecHal(m_encodeCtx->dwNumSlices); + ClearPicParams(); if (VA_STATUS_SUCCESS != status) { DDI_ASSERTMESSAGE("DDI:DdiEncode_EncodeInCodecHal return failure."); @@ -1354,3 +1355,7 @@ uint32_t DdiEncodeBase::getQMatrixBufferSize() { return 0xffffffff; } + +void DdiEncodeBase::ClearPicParams() +{ +} diff --git a/media_driver/linux/common/codec/ddi/media_ddi_encode_base.h b/media_driver/linux/common/codec/ddi/media_ddi_encode_base.h index 0da0f0efea..aacf77fd42 100644 --- a/media_driver/linux/common/codec/ddi/media_ddi_encode_base.h +++ b/media_driver/linux/common/codec/ddi/media_ddi_encode_base.h @@ -306,6 +306,14 @@ class DdiEncodeBase : public DdiMediaBase DDI_MEDIA_CONTEXT *mediaCtx, void * ptr) = 0; + //! + //! \brief Clear picture params + //! \details Clear picture params called by EndPicture + //! + //! \return void + //! + virtual void ClearPicParams(); + //! //! \brief get Slice Parameter Buffer Size //!