Mercurial > libavcodec.hg
comparison utils.c @ 9415:141badec76fc libavcodec
Add a av_fast_malloc function and replace several uses of av_fast_realloc,
thus avoiding potential memleaks and pointless memcpys.
| author | reimar |
|---|---|
| date | Sun, 12 Apr 2009 13:17:37 +0000 |
| parents | d31c367da415 |
| children | f522c8e05a29 |
comparison
equal
deleted
inserted
replaced
| 9414:5a738e8f9524 | 9415:141badec76fc |
|---|---|
| 76 ptr= av_realloc(ptr, *size); | 76 ptr= av_realloc(ptr, *size); |
| 77 if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now | 77 if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now |
| 78 *size= 0; | 78 *size= 0; |
| 79 | 79 |
| 80 return ptr; | 80 return ptr; |
| 81 } | |
| 82 | |
| 83 void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size) | |
| 84 { | |
| 85 void **p = ptr; | |
| 86 if (min_size < *size) | |
| 87 return; | |
| 88 *size= FFMAX(17*min_size/16 + 32, min_size); | |
| 89 av_free(*p); | |
| 90 *p = av_malloc(*size); | |
| 91 if (!*p) *size = 0; | |
| 81 } | 92 } |
| 82 | 93 |
| 83 /* encoder management */ | 94 /* encoder management */ |
| 84 static AVCodec *first_avcodec = NULL; | 95 static AVCodec *first_avcodec = NULL; |
| 85 | 96 |
