[FFmpeg-devel] Patch: explicitly initialize AVFormatContext *ic = NULL

avcoder ffmpeg
Thu Jul 9 16:59:56 CEST 2009


Dear:

"
    Fix mem leak when user preallocates an AVFormatContext, passes it to
    av_open_input_file(), but the file does not exist.
    Patch by Art Clarke a$(surname) xuggle com


    git-svn-id: file:///var/local/repositories/ffmpeg/trunk at 19370
9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
"

The commit will cause error when calling av_freep() at the end of
av_open_input_file() if we fail to explicitly initialize the args:
AVFormatContext **ic_ptr in calling routine.

 fail:
    av_freep(&pd->buf);
    if (pb)
        url_fclose(pb);
    av_freep(ic_ptr);//--->here
    return err;

Patch attached:

diff --git a/ffmpeg.c b/ffmpeg.c
index 22bfed8..95f120c 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -473,7 +473,7 @@ static int av_exit(int ret)
 static int read_ffserver_streams(AVFormatContext *s, const char *filename)
 {
     int i, err;
-    AVFormatContext *ic;
+    AVFormatContext *ic = NULL;
     int nopts = 0;

     err = av_open_input_file(&ic, filename, NULL, FFM_PACKET_SIZE, NULL);
@@ -2848,7 +2848,7 @@ static enum CodecID find_codec_or_die(const char
*name, int type, int encoder)

 static void opt_input_file(const char *filename)
 {
-    AVFormatContext *ic;
+    AVFormatContext *ic = NULL;
     AVFormatParameters params, *ap = ¶ms;
     int err, i, ret, rfps, rfps_base;
     int64_t timestamp;
diff --git a/ffplay.c b/ffplay.c
index 5f88a46..8bca4e3 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1898,7 +1898,7 @@ static int decode_interrupt_cb(void)
 static int decode_thread(void *arg)
 {
     VideoState *is = arg;
-    AVFormatContext *ic;
+    AVFormatContext *ic = NULL;
     int err, i, ret, video_index, audio_index, subtitle_index;
     AVPacket pkt1, *pkt = &pkt1;
     AVFormatParameters params, *ap = ¶ms;
diff --git a/ffserver.c b/ffserver.c
index 61ecf20..8f31377 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -1957,7 +1957,7 @@ static int open_input_stream(HTTPContext *c,
const char *info)
 {
     char buf[128];
     char input_filename[1024];
-    AVFormatContext *s;
+    AVFormatContext *s = NULL;
     int buf_size, i, ret;
     int64_t stream_pos;

@@ -3395,7 +3395,7 @@ static void extract_mpeg4_header(AVFormatContext *infile)
 static void build_file_streams(void)
 {
     FFStream *stream, *stream_next;
-    AVFormatContext *infile;
+    AVFormatContext *infile = NULL;
     int i, ret;

     /* gather all streams */
@@ -3476,7 +3476,7 @@ static void build_feed_streams(void)

         if (url_exist(feed->feed_filename)) {
             /* See if it matches */
-            AVFormatContext *s;
+            AVFormatContext *s = NULL;
             int matches = 0;

             if (av_open_input_file(&s, feed->feed_filename, NULL,
FFM_PACKET_SIZE, NULL) >= 0) {
diff --git a/tests/seek_test.c b/tests/seek_test.c
index 7d64058..ec8a625 100644
--- a/tests/seek_test.c
+++ b/tests/seek_test.c
@@ -33,7 +33,7 @@
 int main(int argc, char **argv)
 {
     const char *filename;
-    AVFormatContext *ic;
+    AVFormatContext *ic = NULL;
     int i, ret, stream_id;
     int64_t timestamp;
     AVFormatParameters params, *ap= ¶ms;
diff --git a/tools/pktdumper.c b/tools/pktdumper.c
index f7ac83d..9724712 100644
--- a/tools/pktdumper.c
+++ b/tools/pktdumper.c
@@ -44,7 +44,7 @@ int main(int argc, char **argv)
 {
     char fntemplate[PATH_MAX];
     char pktfilename[PATH_MAX];
-    AVFormatContext *fctx;
+    AVFormatContext *fctx = NULL;
     AVPacket pkt;
     int64_t pktnum = 0;
     int64_t maxpkts = 0;

-- 
-----------------------------------------------------------------------------------------
My key fingerprint: d1:03:f5:32:26:ff:d7:3c:e4:42:e3:51:ec:92:78:b2
Inspired by http://www.nextplayer.net. Your potential. Our passion.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AVFormatContext_pointer_init.diff
Type: application/octet-stream
Size: 2861 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090709/fca42529/attachment.obj>



More information about the ffmpeg-devel mailing list