]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_av] Fix crash on `av show codecs` and `av show formats`. 27/head
authorAndrey Volk <andywolk@gmail.com>
Tue, 1 Oct 2019 08:14:56 +0000 (12:14 +0400)
committerAndrey Volk <andywolk@gmail.com>
Tue, 1 Oct 2019 09:02:39 +0000 (13:02 +0400)
src/mod/applications/mod_av/avcodec.c
src/mod/applications/mod_av/avformat.c

index 0812fabbb3e1c6e1542b79213fc3b86b58733b4b..4de116fec9273ec1ef429820a0995096270709c1 100644 (file)
@@ -1836,15 +1836,13 @@ static char get_media_type_char(enum AVMediaType type)
        }
 }
 
-static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev,
+static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev, void **index,
                                                                                int encoder)
 {
 #if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,10,100))
        while ((prev = av_codec_next(prev))) {
 #else
-       void *i;
-
-       while ((prev = av_codec_iterate(&i))) {
+       while ((prev = av_codec_iterate(index))) {
 #endif
                if (prev->id == id &&
                        (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev)))
@@ -1887,10 +1885,11 @@ static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
 static void print_codecs_for_id(switch_stream_handle_t *stream, enum AVCodecID id, int encoder)
 {
        const AVCodec *codec = NULL;
+       void *index = 0;
 
        stream->write_function(stream, " (%s: ", encoder ? "encoders" : "decoders");
 
-       while ((codec = next_codec_for_id(id, codec, encoder))) {
+       while ((codec = next_codec_for_id(id, codec, &index, encoder))) {
                stream->write_function(stream, "%s ", codec->name);
        }
 
@@ -1916,6 +1915,7 @@ void show_codecs(switch_stream_handle_t *stream)
        for (i = 0; i < nb_codecs; i++) {
                const AVCodecDescriptor *desc = codecs[i];
                const AVCodec *codec = NULL;
+               void *index = 0;
 
                stream->write_function(stream, " ");
                stream->write_function(stream, avcodec_find_decoder(desc->id) ? "D" : ".");
@@ -1930,14 +1930,14 @@ void show_codecs(switch_stream_handle_t *stream)
 
                /* print decoders/encoders when there's more than one or their
                 * names are different from codec name */
-               while ((codec = next_codec_for_id(desc->id, codec, 0))) {
+               while ((codec = next_codec_for_id(desc->id, codec, &index, 0))) {
                        if (strcmp(codec->name, desc->name)) {
                                print_codecs_for_id(stream ,desc->id, 0);
                                break;
                        }
                }
-               codec = NULL;
-               while ((codec = next_codec_for_id(desc->id, codec, 1))) {
+               codec = NULL; index = 0;
+               while ((codec = next_codec_for_id(desc->id, codec, &index, 1))) {
                        if (strcmp(codec->name, desc->name)) {
                                print_codecs_for_id(stream, desc->id, 1);
                                break;
index 986bfed1254f3e68d785f8bf4faabf5e598b415b..2e0c7de7ab65985a968efada88794c3c75a22415 100644 (file)
@@ -1029,7 +1029,7 @@ void show_formats(switch_stream_handle_t *stream) {
 #if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58,9,100))
                while ((ofmt = av_oformat_next(ofmt))) {
 #else
-               void *i;
+               void *i = 0;
 
                while ((ofmt = av_muxer_iterate(&i))) {
 #endif
@@ -1047,6 +1047,7 @@ void show_formats(switch_stream_handle_t *stream) {
 #if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58,9,100))
                while ((ifmt = av_iformat_next(ifmt))) {
 #else
+               i = 0;
                while ((ifmt = av_demuxer_iterate(&i))) {
 #endif
                        is_dev = is_device(ifmt->priv_class);