[FFmpeg-devel] avformat/mp3enc: flush buffered packets if referencing fails

Submitted by James Almer on Oct. 6, 2017, 6:58 p.m.

Details

Message ID 20171006185859.8380-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Oct. 6, 2017, 6:58 p.m.
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mp3enc.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Michael Niedermayer Oct. 7, 2017, 12:42 a.m.
On Fri, Oct 06, 2017 at 03:58:59PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/mp3enc.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)

LGTM

thx

[...]
James Almer Oct. 7, 2017, 1:12 a.m.
On 10/6/2017 9:42 PM, Michael Niedermayer wrote:
> On Fri, Oct 06, 2017 at 03:58:59PM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavformat/mp3enc.c | 9 ++-------
>>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> LGTM
> 
> thx

Pushed, thanks.

Patch hide | download patch | download mbox

diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index 826878eca1..c63909393d 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -516,19 +516,14 @@  static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
             /* buffer audio packets until we get all the pictures */
             AVPacketList *pktl = av_mallocz(sizeof(*pktl));
             int ret;
-            if (!pktl) {
+            if (!pktl || av_packet_ref(&pktl->pkt, pkt) < 0) {
+                av_freep(&pktl);
                 av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n");
                 mp3->pics_to_write = 0;
                 mp3_queue_flush(s);
                 return mp3_write_audio_packet(s, pkt);
             }
 
-            ret = av_packet_ref(&pktl->pkt, pkt);
-            if (ret < 0) {
-                av_freep(&pktl);
-                return ret;
-            }
-
             if (mp3->queue_end)
                 mp3->queue_end->next = pktl;
             else