diff mbox

[FFmpeg-devel,1/3] avcodec/h264_metadata: fix memory leak in case of output packet creation failure

Message ID 20180320035528.2356-1-jamrial@gmail.com
State Accepted
Headers show

Commit Message

James Almer March 20, 2018, 3:55 a.m. UTC
Some function calls may fail after the output packet is initialized.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/h264_metadata_bsf.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

James Almer March 20, 2018, 5:46 p.m. UTC | #1
On 3/20/2018 12:55 AM, James Almer wrote:
> Some function calls may fail after the output packet is initialized.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/h264_metadata_bsf.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
> index e1f0c43b71..0381e9d102 100644
> --- a/libavcodec/h264_metadata_bsf.c
> +++ b/libavcodec/h264_metadata_bsf.c
> @@ -545,6 +545,8 @@ fail:
>      ff_cbs_fragment_uninit(ctx->cbc, au);
>      av_freep(&displaymatrix_side_data);
>  
> +    if (err < 0)
> +        av_packet_unref(&out);

Err, it's meant to be out, not &out.

Fixed locally on all three patches.

>      av_packet_free(&in);
>  
>      return err;
>
James Almer March 20, 2018, 9:33 p.m. UTC | #2
On 3/20/2018 2:46 PM, James Almer wrote:
> On 3/20/2018 12:55 AM, James Almer wrote:
>> Some function calls may fail after the output packet is initialized.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavcodec/h264_metadata_bsf.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
>> index e1f0c43b71..0381e9d102 100644
>> --- a/libavcodec/h264_metadata_bsf.c
>> +++ b/libavcodec/h264_metadata_bsf.c
>> @@ -545,6 +545,8 @@ fail:
>>      ff_cbs_fragment_uninit(ctx->cbc, au);
>>      av_freep(&displaymatrix_side_data);
>>  
>> +    if (err < 0)
>> +        av_packet_unref(&out);
> 
> Err, it's meant to be out, not &out.
> 
> Fixed locally on all three patches.
> 
>>      av_packet_free(&in);
>>  
>>      return err;
>>

Set approved by jkqxz on IRC and pushed.
diff mbox

Patch

diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index e1f0c43b71..0381e9d102 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -545,6 +545,8 @@  fail:
     ff_cbs_fragment_uninit(ctx->cbc, au);
     av_freep(&displaymatrix_side_data);
 
+    if (err < 0)
+        av_packet_unref(&out);
     av_packet_free(&in);
 
     return err;