diff mbox series

[FFmpeg-devel,1/3] avcodec/libmp3lame: Remove redundant av_packet_unref()

Message ID AS8P250MB07440200D0F1F858D98D045D8FB99@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit af26a8ffbb8a553a890eefefd019cf2b1ccbdc84
Headers show
Series [FFmpeg-devel,1/3] avcodec/libmp3lame: Remove redundant av_packet_unref() | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt March 13, 2023, 4:13 a.m. UTC
The AVPacket given to an encoder's encode callback
is unreferenced generically on error.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
This stuff should probably be moved into the AudioFrameQueue
someday.

 libavcodec/libmp3lame.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Andreas Rheinhardt March 15, 2023, 4 p.m. UTC | #1
Andreas Rheinhardt:
> The AVPacket given to an encoder's encode callback
> is unreferenced generically on error.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> This stuff should probably be moved into the AudioFrameQueue
> someday.
> 
>  libavcodec/libmp3lame.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
> index 26e58baa3d..e119189f2a 100644
> --- a/libavcodec/libmp3lame.c
> +++ b/libavcodec/libmp3lame.c
> @@ -280,17 +280,14 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>          // Check if subtraction resulted in an overflow
>          if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) {
>              av_log(avctx, AV_LOG_ERROR, "discard padding overflow\n");
> -            av_packet_unref(avpkt);
>              return AVERROR(EINVAL);
>          }
>          if ((!s->delay_sent && avctx->initial_padding > 0) || discard_padding > 0) {
>              uint8_t* side_data = av_packet_new_side_data(avpkt,
>                                                           AV_PKT_DATA_SKIP_SAMPLES,
>                                                           10);
> -            if(!side_data) {
> -                av_packet_unref(avpkt);
> +            if (!side_data)
>                  return AVERROR(ENOMEM);
> -            }
>              if (!s->delay_sent) {
>                  AV_WL32(side_data, avctx->initial_padding);
>                  s->delay_sent = 1;

Will apply this patchset tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 26e58baa3d..e119189f2a 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -280,17 +280,14 @@  static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         // Check if subtraction resulted in an overflow
         if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) {
             av_log(avctx, AV_LOG_ERROR, "discard padding overflow\n");
-            av_packet_unref(avpkt);
             return AVERROR(EINVAL);
         }
         if ((!s->delay_sent && avctx->initial_padding > 0) || discard_padding > 0) {
             uint8_t* side_data = av_packet_new_side_data(avpkt,
                                                          AV_PKT_DATA_SKIP_SAMPLES,
                                                          10);
-            if(!side_data) {
-                av_packet_unref(avpkt);
+            if (!side_data)
                 return AVERROR(ENOMEM);
-            }
             if (!s->delay_sent) {
                 AV_WL32(side_data, avctx->initial_padding);
                 s->delay_sent = 1;