diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2009-04-12 13:17:37 +0000 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2009-04-12 13:17:37 +0000 |
commit | 238ef6dadd13b9a867eaa7382bdba751e25c40b9 (patch) | |
tree | ac0228289581351403ee3f1d9ad187919d498fbb /libavcodec/utils.c | |
parent | 9bf993a5b5f8bf10c590d83c795467606f92cf6e (diff) | |
download | ffmpeg-238ef6dadd13b9a867eaa7382bdba751e25c40b9.tar.gz |
Add a av_fast_malloc function and replace several uses of av_fast_realloc,
thus avoiding potential memleaks and pointless memcpys.
Originally committed as revision 18470 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 7a24a4d246..a37ace9cc5 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -80,6 +80,17 @@ void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) return ptr; } +void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size) +{ + void **p = ptr; + if (min_size < *size) + return; + *size= FFMAX(17*min_size/16 + 32, min_size); + av_free(*p); + *p = av_malloc(*size); + if (!*p) *size = 0; +} + /* encoder management */ static AVCodec *first_avcodec = NULL; |