diff mbox

[FFmpeg-devel] Fixing small memory leak when wrapping texture in AVD3D11FrameDescriptor

Message ID 1509856989-4414-1-git-send-email-wesselsga@gmail.com
State Accepted
Commit 2c2f25eb8920129ef3cfe6da2e1cefdedc485965
Headers show

Commit Message

Greg Wessels Nov. 5, 2017, 4:43 a.m. UTC
---
 libavutil/hwcontext_d3d11va.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Aaron Levinson Nov. 8, 2017, 1:50 a.m. UTC | #1
On 11/4/2017 9:43 PM, Greg Wessels wrote:
> ---
>   libavutil/hwcontext_d3d11va.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
> index 52683b9..65dd665 100644
> --- a/libavutil/hwcontext_d3d11va.c
> +++ b/libavutil/hwcontext_d3d11va.c
> @@ -123,6 +123,7 @@ static void d3d11va_frames_uninit(AVHWFramesContext *ctx)
>   static void free_texture(void *opaque, uint8_t *data)
>   {
>       ID3D11Texture2D_Release((ID3D11Texture2D *)opaque);
> +    av_free(data);
>   }
>   
>   static AVBufferRef *wrap_texture_buf(ID3D11Texture2D *tex, int index)
> 

LGTM.  I've also noticed a memory leak with hardware-accelerated D3D11 
H.264 decoding, and this patch fixes the issue.  The actual memory leak 
originates from wrap_texture_buf() in the same file from the following line:

     AVD3D11FrameDescriptor *desc = av_mallocz(sizeof(*desc));

and there will be one leak per surface per hardware decoding session. 
The number of surfaces can vary, but for H.264 and HEVC, it is equal to 
20 (4 + 16).  So, for H.264, there will be 20 leaks per decoding session.

It would be helpful to see this committed soon.  Additionally, I looked 
at the libav source base, and this issue exists there as well.

Aaron Levinson
James Almer Nov. 8, 2017, 2:01 a.m. UTC | #2
On 11/7/2017 10:50 PM, Aaron Levinson wrote:
> On 11/4/2017 9:43 PM, Greg Wessels wrote:
>> ---
>>   libavutil/hwcontext_d3d11va.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/libavutil/hwcontext_d3d11va.c
>> b/libavutil/hwcontext_d3d11va.c
>> index 52683b9..65dd665 100644
>> --- a/libavutil/hwcontext_d3d11va.c
>> +++ b/libavutil/hwcontext_d3d11va.c
>> @@ -123,6 +123,7 @@ static void
>> d3d11va_frames_uninit(AVHWFramesContext *ctx)
>>   static void free_texture(void *opaque, uint8_t *data)
>>   {
>>       ID3D11Texture2D_Release((ID3D11Texture2D *)opaque);
>> +    av_free(data);
>>   }
>>     static AVBufferRef *wrap_texture_buf(ID3D11Texture2D *tex, int index)
>>
> 
> LGTM.  I've also noticed a memory leak with hardware-accelerated D3D11
> H.264 decoding, and this patch fixes the issue.  The actual memory leak
> originates from wrap_texture_buf() in the same file from the following
> line:
> 
>     AVD3D11FrameDescriptor *desc = av_mallocz(sizeof(*desc));
> 
> and there will be one leak per surface per hardware decoding session.
> The number of surfaces can vary, but for H.264 and HEVC, it is equal to
> 20 (4 + 16).  So, for H.264, there will be 20 leaks per decoding session.
> 
> It would be helpful to see this committed soon.  Additionally, I looked
> at the libav source base, and this issue exists there as well.
> 
> Aaron Levinson

I'm not the maintainer of hwcontext_d3d11va, but the patch is pretty
straightforward, so pushed.
diff mbox

Patch

diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index 52683b9..65dd665 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -123,6 +123,7 @@  static void d3d11va_frames_uninit(AVHWFramesContext *ctx)
 static void free_texture(void *opaque, uint8_t *data)
 {
     ID3D11Texture2D_Release((ID3D11Texture2D *)opaque);
+    av_free(data);
 }
 
 static AVBufferRef *wrap_texture_buf(ID3D11Texture2D *tex, int index)