diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index e6fa42cdd246bdd4d39ff57a8660fae4421edf9b..44a115858d3b79d48c4ffec43b8dfd4acfa711eb 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2096,8 +2096,7 @@ void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size); /* for static data only */ /* call av_free_static to release all staticaly allocated tables */ void av_free_static(void); -void *__av_mallocz_static(void** location, unsigned int size); -#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s) +void *av_mallocz_static(unsigned int size); /* add by bero : in adx.c */ int is_adx(const unsigned char *buf,size_t bufsize); diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 58caf65109e7b702f7475fdda43c830871ef9ac0..a9eed4e36a383b303869c99225121fd1339d115e 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -400,11 +400,11 @@ static int decode_init(AVCodecContext * avctx) } /* compute n ^ (4/3) and store it in mantissa/exp format */ - if (!av_mallocz_static(&table_4_3_exp, - TABLE_4_3_SIZE * sizeof(table_4_3_exp[0]))) + table_4_3_exp= av_mallocz_static(TABLE_4_3_SIZE * sizeof(table_4_3_exp[0])); + if(!table_4_3_exp) return -1; - if (!av_mallocz_static(&table_4_3_value, - TABLE_4_3_SIZE * sizeof(table_4_3_value[0]))) + table_4_3_value= av_mallocz_static(TABLE_4_3_SIZE * sizeof(table_4_3_value[0])); + if(!table_4_3_value) return -1; int_pow_init(); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index b6b6059e9962967c05764289da21dc504829f20b..df469300d8de9a782ec700c340877772163ece81 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -66,41 +66,35 @@ void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) } -/* allocation of static arrays - do not use for normal allocation */ static unsigned int last_static = 0; -static char*** array_static = NULL; +static unsigned int allocated_static = 0; +static void** array_static = NULL; static const unsigned int grow_static = 64; // ^2 -void *__av_mallocz_static(void** location, unsigned int size) + +/** + * allocation of static arrays - do not use for normal allocation. + */ +void *av_mallocz_static(unsigned int size) { - unsigned int l = (last_static + grow_static) & ~(grow_static - 1); void *ptr = av_mallocz(size); - if (!ptr) - return NULL; - - if (location) - { - if (l > last_static) - array_static = av_realloc(array_static, l); - array_static[last_static++] = (char**) location; - *location = ptr; + + if(ptr){ + array_static =av_fast_realloc(array_static, &allocated_static, last_static+1); + array_static[last_static++] = ptr; } + return ptr; } -/* free all static arrays and reset pointers to 0 */ + +/** + * free all static arrays and reset pointers to 0. + */ void av_free_static(void) { - if (array_static) - { - unsigned i; - for (i = 0; i < last_static; i++) - { - av_free(*array_static[i]); - *array_static[i] = NULL; - } - av_free(array_static); - array_static = 0; + while(last_static){ + av_freep(&array_static[--last_static]); } - last_static = 0; + av_freep(&array_static); } /**