[FFmpeg-cvslog] examples: Add av_freep to avoid potential memory leak

Jiasheng Jiang git at videolan.org
Mon Aug 4 23:58:00 EEST 2025


ffmpeg | branch: release/7.0 | Jiasheng Jiang <jiashengjiangcool at gmail.com> | Sat Aug  2 23:28:48 2025 +0000| [8fb86b863af61e3160d83abbfec9252ec9c6a173] | committer: Michael Niedermayer

examples: Add av_freep to avoid potential memory leak

Add av_freep() to free avio_ctx_buffer if avio_alloc_context fails
to avoid potential memory leak.

Fixes: 5fc4dea39c ("examples: add avio_reading.c example")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool at gmail.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 9ca58424ded24e931fed329174c28244b67d5670)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

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

 doc/examples/avio_read_callback.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/examples/avio_read_callback.c b/doc/examples/avio_read_callback.c
index 4cf81ad72e..aa4a5c5b85 100644
--- a/doc/examples/avio_read_callback.c
+++ b/doc/examples/avio_read_callback.c
@@ -95,6 +95,7 @@ int main(int argc, char *argv[])
     avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size,
                                   0, &bd, &read_packet, NULL, NULL);
     if (!avio_ctx) {
+        av_freep(&avio_ctx_buffer);
         ret = AVERROR(ENOMEM);
         goto end;
     }



More information about the ffmpeg-cvslog mailing list