diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2003-01-23 23:03:09 +0000 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2003-01-23 23:03:09 +0000 |
commit | 8e1e6f31c142aeb27d3dd7df539c47b35d7eb903 (patch) | |
tree | a1e73532f1654c52016b9ccaf233aa4add95dfd3 /libavcodec/utils.c | |
parent | 47e2a6e6c521a007f78b23ed554a1b81defef936 (diff) | |
download | ffmpeg-8e1e6f31c142aeb27d3dd7df539c47b35d7eb903.tar.gz |
use av_malloc() functions - added av_strdup and av_realloc()
Originally committed as revision 1505 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index ba47785ffc..e9e6725221 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -33,6 +33,32 @@ void *av_mallocz(unsigned int size) return ptr; } +char *av_strdup(const char *s) +{ + char *ptr; + int len; + len = strlen(s) + 1; + ptr = av_malloc(len); + if (!ptr) + return NULL; + memcpy(ptr, s, len); + return ptr; +} + +/** + * realloc which does nothing if the block is large enough + */ +void *av_fast_realloc(void *ptr, int *size, int min_size) +{ + if(min_size < *size) + return ptr; + + *size= min_size + 10*1024; + + return av_realloc(ptr, *size); +} + + /* allocation of static arrays - do not use for normal allocation */ static unsigned int last_static = 0; static char*** array_static = NULL; @@ -47,7 +73,7 @@ void *__av_mallocz_static(void** location, unsigned int size) if (location) { if (l > last_static) - array_static = realloc(array_static, l); + array_static = av_realloc(array_static, l); array_static[last_static++] = (char**) location; *location = ptr; } @@ -61,10 +87,10 @@ void av_free_static() unsigned i; for (i = 0; i < last_static; i++) { - free(*array_static[i]); + av_free(*array_static[i]); *array_static[i] = NULL; } - free(array_static); + av_free(array_static); array_static = 0; } last_static = 0; |