diff mbox

[FFmpeg-devel,01/10] avformat/mpjpegdec: Avoid allocation of AVIOContext

Message ID 20191006050120.26807-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 670fd3b0ec8f81f7cb69932715562ddcd55096ec
Headers show

Commit Message

Andreas Rheinhardt Oct. 6, 2019, 5:01 a.m. UTC
Put an AVIOContext whose lifetime doesn't extend beyond the function where
it is allocated on the stack instead of allocating and freeing it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/mpjpegdec.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Michael Niedermayer Oct. 6, 2019, 5:53 p.m. UTC | #1
On Sun, Oct 06, 2019 at 07:01:11AM +0200, Andreas Rheinhardt wrote:
> Put an AVIOContext whose lifetime doesn't extend beyond the function where
> it is allocated on the stack instead of allocating and freeing it.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/mpjpegdec.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c
index e653b5cc93..84130ab718 100644
--- a/libavformat/mpjpegdec.c
+++ b/libavformat/mpjpegdec.c
@@ -113,20 +113,16 @@  static int mpjpeg_read_close(AVFormatContext *s)
 
 static int mpjpeg_read_probe(const AVProbeData *p)
 {
-    AVIOContext *pb;
+    AVIOContext pb;
     int ret = 0;
     int size = 0;
 
     if (p->buf_size < 2 || p->buf[0] != '-' || p->buf[1] != '-')
         return 0;
 
-    pb = avio_alloc_context(p->buf, p->buf_size, 0, NULL, NULL, NULL, NULL);
-    if (!pb)
-        return 0;
-
-    ret = (parse_multipart_header(pb, &size, "--", NULL) >= 0) ? AVPROBE_SCORE_MAX : 0;
+    ffio_init_context(&pb, p->buf, p->buf_size, 0, NULL, NULL, NULL, NULL);
 
-    avio_context_free(&pb);
+    ret = (parse_multipart_header(&pb, &size, "--", NULL) >= 0) ? AVPROBE_SCORE_MAX : 0;
 
     return ret;
 }