Mercurial > libavcodec.hg
comparison bitstream.c @ 6944:030cc3278868 libavcodec
As *_static are not deallocated anymore except on program termination
we do not need to keep track of them anymore.
Fixes CID117 RUN2 and various race conditions.
| author | michael |
|---|---|
| date | Fri, 30 May 2008 23:26:09 +0000 |
| parents | dcb0105c2150 |
| children | 7128fa020b0e |
comparison
equal
deleted
inserted
replaced
| 6943:dcb0105c2150 | 6944:030cc3278868 |
|---|---|
| 40 * and should correctly use static arrays | 40 * and should correctly use static arrays |
| 41 */ | 41 */ |
| 42 attribute_deprecated av_alloc_size(2) | 42 attribute_deprecated av_alloc_size(2) |
| 43 static void *ff_realloc_static(void *ptr, unsigned int size); | 43 static void *ff_realloc_static(void *ptr, unsigned int size); |
| 44 | 44 |
| 45 static unsigned int last_static = 0; | |
| 46 static unsigned int allocated_static = 0; | |
| 47 static void** array_static = NULL; | |
| 48 | |
| 49 static void *av_mallocz_static(unsigned int size) | 45 static void *av_mallocz_static(unsigned int size) |
| 50 { | 46 { |
| 51 void *ptr = av_mallocz(size); | 47 return av_mallocz(size); |
| 52 | |
| 53 if(ptr){ | |
| 54 array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1)); | |
| 55 if(!array_static) | |
| 56 return NULL; | |
| 57 array_static[last_static++] = ptr; | |
| 58 } | |
| 59 | |
| 60 return ptr; | |
| 61 } | 48 } |
| 62 | 49 |
| 63 static void *ff_realloc_static(void *ptr, unsigned int size) | 50 static void *ff_realloc_static(void *ptr, unsigned int size) |
| 64 { | 51 { |
| 65 int i; | 52 return av_realloc(ptr, size); |
| 66 if(!ptr) | |
| 67 return av_mallocz_static(size); | |
| 68 /* Look for the old ptr */ | |
| 69 for(i = 0; i < last_static; i++) { | |
| 70 if(array_static[i] == ptr) { | |
| 71 array_static[i] = av_realloc(array_static[i], size); | |
| 72 return array_static[i]; | |
| 73 } | |
| 74 } | |
| 75 return NULL; | |
| 76 | |
| 77 } | 53 } |
| 78 | 54 |
| 79 void align_put_bits(PutBitContext *s) | 55 void align_put_bits(PutBitContext *s) |
| 80 { | 56 { |
| 81 #ifdef ALT_BITSTREAM_WRITER | 57 #ifdef ALT_BITSTREAM_WRITER |
