The mpegts_write_end() function in libavformat/mpegtsenc.c trys to
run av_freep() on the adts data part of the mpegts structure even
when it wasn't allocated (non AAC based audio in mpegts).  This
has given segfaults, seems to rarely happen but it does, and code
seems to just "make sense".  Plus my check in the diff here which
is commented out, can be uncommented and it'll show the problem is
an issue.

Backtrace: 
#0  *__GI___libc_free (mem=0x99c3003a6edb869e) at malloc.c:3709
#1  0x000000000040a071 in av_free (ptr=<value optimized out>)
    at libavutil/mem.c:146
#2  av_freep (ptr=<value optimized out>) at libavutil/mem.c:153
#3  0x0000000000453757 in mpegts_write_end (s=0x132d8c0)
    at libavformat/mpegtsenc.c:934
#4  0x000000000048ea32 in av_write_trailer (s=0x132d8c0)
    at libavformat/utils.c:3113
#5  0x0000000000408762 in close_file (SLconfig=0x7fffffffda60, is_video=1)
    at slicer.c:1045
#6  0x0000000000408835 in stop_mux (SLconfig=0x7fffffffda60, is_video=1)
    at slicer.c:1073
#7  0x00000000004076fc in main (argc=4, argv=0x7fffffffe558) at slicer.c:754

Thanks,
Chris

-- 
Chris Kennedy
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 7e96472..8a5f0aa 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -989,7 +989,14 @@ static int mpegts_write_end(AVFormatContext *s)
             mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
                              ts_st->payload_pts, ts_st->payload_dts);
         }
-        av_freep(&ts_st->adts);
+       //if (ts_st->adts)
+       //      av_log(NULL, AV_LOG_WARNING, "ADTS is allocated\n");
+       //else
+       //      av_log(NULL, AV_LOG_WARNING, "ADTS is NULL\n");
+       if (st->codec->codec_id == CODEC_ID_AAC &&
+            st->codec->extradata_size > 0) {
+            av_freep(&ts_st->adts);
+       }
     }
     avio_flush(s->pb);
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to