A bit more complex than e.g. adding it to the context, but
using the context for something that will be used only during
initialization seemed a bit wasteful.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
... | ... |
@@ -862,9 +862,11 @@ static av_cold int encode_init(AVCodecContext *avctx) |
862 | 862 |
} |
863 | 863 |
if (avctx->stats_in) { |
864 | 864 |
char *p = avctx->stats_in; |
865 |
- uint8_t best_state[256][256]; |
|
865 |
+ uint8_t (*best_state)[256] = av_malloc_array(256, 256); |
|
866 | 866 |
int gob_count = 0; |
867 | 867 |
char *next; |
868 |
+ if (!best_state) |
|
869 |
+ return AVERROR(ENOMEM); |
|
868 | 870 |
|
869 | 871 |
av_assert0(s->version >= 2); |
870 | 872 |
|
... | ... |
@@ -875,6 +877,7 @@ static av_cold int encode_init(AVCodecContext *avctx) |
875 | 875 |
if (next == p) { |
876 | 876 |
av_log(avctx, AV_LOG_ERROR, |
877 | 877 |
"2Pass file invalid at %d %d [%s]\n", j, i, p); |
878 |
+ av_freep(&best_state); |
|
878 | 879 |
return AVERROR_INVALIDDATA; |
879 | 880 |
} |
880 | 881 |
p = next; |
... | ... |
@@ -888,6 +891,7 @@ static av_cold int encode_init(AVCodecContext *avctx) |
888 | 888 |
av_log(avctx, AV_LOG_ERROR, |
889 | 889 |
"2Pass file invalid at %d %d %d %d [%s]\n", |
890 | 890 |
i, j, k, m, p); |
891 |
+ av_freep(&best_state); |
|
891 | 892 |
return AVERROR_INVALIDDATA; |
892 | 893 |
} |
893 | 894 |
p = next; |
... | ... |
@@ -896,6 +900,7 @@ static av_cold int encode_init(AVCodecContext *avctx) |
896 | 896 |
gob_count = strtol(p, &next, 0); |
897 | 897 |
if (next == p || gob_count <= 0) { |
898 | 898 |
av_log(avctx, AV_LOG_ERROR, "2Pass file invalid\n"); |
899 |
+ av_freep(&best_state); |
|
899 | 900 |
return AVERROR_INVALIDDATA; |
900 | 901 |
} |
901 | 902 |
p = next; |
... | ... |
@@ -933,6 +938,7 @@ static av_cold int encode_init(AVCodecContext *avctx) |
933 | 933 |
} |
934 | 934 |
} |
935 | 935 |
} |
936 |
+ av_freep(&best_state); |
|
936 | 937 |
} |
937 | 938 |
|
938 | 939 |
if (s->version > 1) { |