X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=libavcodec%2Fbitstream.c;h=95e5092b447b3379814e34dd5ab8e2a867ef41f3;hb=042af30303ead6a094c6608ca6f5419bb130ce88;hp=be8a0f634dc60013b46c86999bab17b1285e93c6;hpb=a7e3b271fc9a91c5d2e4df32e70e525c15c6d3ef;p=ffmpeg diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index be8a0f634dc..95e5092b447 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -162,9 +162,9 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, uint32_t code; volatile VLC_TYPE (* volatile table)[2]; // the double volatile is needed to prevent an internal compiler error in gcc 4.2 - table_size = 1 << table_nb_bits; if (table_nb_bits > 30) return AVERROR(EINVAL); + table_size = 1 << table_nb_bits; table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC); ff_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size); if (table_index < 0) @@ -266,9 +266,6 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, 'wrap' and 'size' make it possible to use any memory configuration and types (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables. - - 'use_static' should be set to 1 for tables, which should be freed - with av_free_static(), 0 if ff_free_vlc() will be used. */ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, @@ -285,7 +282,6 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, vlc->bits = nb_bits; if (flags & INIT_VLC_USE_NEW_STATIC) { av_assert0(nb_codes + 1 <= FF_ARRAY_ELEMS(localbuf)); - buf = localbuf; localvlc = *vlc_arg; vlc = &localvlc; vlc->table_size = 0; @@ -293,11 +289,13 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, vlc->table = NULL; vlc->table_allocated = 0; vlc->table_size = 0; - + } + if (nb_codes + 1 > FF_ARRAY_ELEMS(localbuf)) { buf = av_malloc_array((nb_codes + 1), sizeof(VLCcode)); if (!buf) return AVERROR(ENOMEM); - } + } else + buf = localbuf; av_assert0(symbols_size <= 2 || !symbols); @@ -309,7 +307,7 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, continue; \ if (buf[j].bits > 3*nb_bits || buf[j].bits>32) { \ av_log(NULL, AV_LOG_ERROR, "Too long VLC (%d) in init_vlc\n", buf[j].bits);\ - if (!(flags & INIT_VLC_USE_NEW_STATIC)) \ + if (buf != localbuf) \ av_free(buf); \ return AVERROR(EINVAL); \ } \ @@ -317,7 +315,7 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, if (buf[j].code >= (1LL<= 0); *vlc_arg = *vlc; } else { - av_free(buf); + if (buf != localbuf) + av_free(buf); if (ret < 0) { av_freep(&vlc->table); return ret;