[FFmpeg-cvslog] avcodec/vorbisenc: fix leak if av_mallocz failed

Lidong Yan git at videolan.org
Sun Jun 29 01:36:30 EEST 2025


ffmpeg | branch: master | Lidong Yan <yldhome2d2 at gmail.com> | Fri Jun 27 22:09:16 2025 +0800| [40a3d35da6ba51e0a4e59e754d033feefafc036d] | committer: Michael Niedermayer

avcodec/vorbisenc: fix leak if av_mallocz failed

In put_main_header(), av_mallocz() allocates memory to local variable
buffer, buffer leaks if av_mallocz() to *out failed. Add av_free(buffer)
before return error code.

Signed-off-by: Lidong Yan <502024330056 at smail.nju.edu.cn>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=40a3d35da6ba51e0a4e59e754d033feefafc036d
---

 libavcodec/vorbisenc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 99ac72c910..b4680a11ed 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -740,8 +740,10 @@ static int put_main_header(vorbis_enc_context *venc, uint8_t **out)
 
     len = hlens[0] + hlens[1] + hlens[2];
     p = *out = av_mallocz(64 + len + len/255);
-    if (!p)
+    if (!p) {
+        av_freep(&buffer);
         return AVERROR(ENOMEM);
+    }
 
     *p++ = 2;
     p += av_xiphlacing(p, hlens[0]);



More information about the ffmpeg-cvslog mailing list