[FFmpeg-devel] [PATCH] avcodec/encode: don't return immediately on failure

James Almer jamrial at gmail.com
Tue Oct 3 20:04:48 EEST 2017


On 10/3/2017 5:23 AM, wm4 wrote:
> On Tue,  3 Oct 2017 01:55:44 -0300
> James Almer <jamrial at gmail.com> wrote:
> 
>> Fixes memleaks introduced by skipping cleanup at the end of the
>> functions.
>>
>> Regression since a22c6a4796ca1f2cbee6784262515da876fbec22.
>>
>> Signed-off-by: James Almer <jamrial at gmail.com>
>> ---
>>  libavcodec/encode.c | 16 ++++++++--------
>>  1 file changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
>> index c152228c92..841a185738 100644
>> --- a/libavcodec/encode.c
>> +++ b/libavcodec/encode.c
>> @@ -225,10 +225,10 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
>>          } else if (!avpkt->buf) {
>>              AVPacket tmp = { 0 };
>>              ret = av_packet_ref(&tmp, avpkt);
>> -            if (ret < 0)
>> -                return ret;
>> -            av_packet_unref(avpkt);
>> -            *avpkt = tmp;
>> +            if (!ret) {
>> +                av_packet_unref(avpkt);
>> +                *avpkt = tmp;
>> +            }
>>          }
>>      }
>>  
>> @@ -324,10 +324,10 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
>>          } else if (!avpkt->buf) {
>>              AVPacket tmp = { 0 };
>>              ret = av_packet_ref(&tmp, avpkt);
>> -            if (ret < 0)
>> -                return ret;
>> -            av_packet_unref(avpkt);
>> -            *avpkt = tmp;
>> +            if (!ret) {
>> +                av_packet_unref(avpkt);
>> +                *avpkt = tmp;
>> +            }
>>          }
>>      }
>>  
> 
> Seems ok if ret is actually checked in the code below. Something like
> "goto cleanup;" on error would be less confusing though.

Did that instead and pushed. Thanks.


More information about the ffmpeg-devel mailing list