diff mbox series

[FFmpeg-devel,2/3] avformat/spdifenc: Fix leak upon error

Message ID 20210222093234.212078-2-andreas.rheinhardt@gmail.com
State Accepted
Commit e38cbb8d19e21af9ea3f947e64bee1d4d362e492
Headers show
Series [FFmpeg-devel,1/3] avformat/wavenc: Fix leak and segfault on reallocation error | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 22, 2021, 9:32 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/spdifenc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index 0288872fd3..c3ba3a1a19 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -122,14 +122,16 @@  static int spdif_header_eac3(AVFormatContext *s, AVPacket *pkt)
     IEC61937Context *ctx = s->priv_data;
     static const uint8_t eac3_repeat[4] = {6, 3, 2, 1};
     int repeat = 1;
+    uint8_t *tmp;
 
     int bsid = pkt->data[5] >> 3;
     if (bsid > 10 && (pkt->data[4] & 0xc0) != 0xc0) /* fscod */
         repeat = eac3_repeat[(pkt->data[4] & 0x30) >> 4]; /* numblkscod */
 
-    ctx->hd_buf[0] = av_fast_realloc(ctx->hd_buf[0], &ctx->hd_buf_size, ctx->hd_buf_filled + pkt->size);
-    if (!ctx->hd_buf[0])
+    tmp = av_fast_realloc(ctx->hd_buf[0], &ctx->hd_buf_size, ctx->hd_buf_filled + pkt->size);
+    if (!tmp)
         return AVERROR(ENOMEM);
+    ctx->hd_buf[0] = tmp;
 
     memcpy(&ctx->hd_buf[0][ctx->hd_buf_filled], pkt->data, pkt->size);