diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2002-05-18 22:59:50 +0000 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2002-05-18 22:59:50 +0000 |
commit | 3123dd793eaf26a4932e4ceeb6d271a4d512bab0 (patch) | |
tree | df0ac09da9ac45ffa5efb2752c61385fe710ff56 | |
parent | 61a4e8ae3b4398adcbf85c68e81a04f31afaec91 (diff) | |
download | ffmpeg-3123dd793eaf26a4932e4ceeb6d271a4d512bab0.tar.gz |
proper memory handling functions
Originally committed as revision 520 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/utils.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 5480494928..cf94531760 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -16,21 +16,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include "common.h" -#include "dsputil.h" #include "avcodec.h" +#include "dsputil.h" #include "mpegvideo.h" #ifdef HAVE_MALLOC_H #include <malloc.h> -#else -#include <stdlib.h> #endif /* memory alloc */ -void *av_mallocz(int size) +void *av_malloc(int size) { void *ptr; #if defined ( ARCH_X86 ) && defined ( HAVE_MEMALIGN ) @@ -53,6 +47,24 @@ void *av_mallocz(int size) return ptr; } +void *av_mallocz(int size) +{ + void *ptr; + ptr = av_malloc(size); + if (!ptr) + return NULL; + memset(ptr, 0, size); + return ptr; +} + +/* NOTE: ptr = NULL is explicetly allowed */ +void av_free(void *ptr) +{ + /* XXX: this test should not be needed on most libcs */ + if (ptr) + free(ptr); +} + /* encoder management */ AVCodec *first_avcodec; @@ -80,9 +92,7 @@ int avcodec_open(AVCodecContext *avctx, AVCodec *codec) } ret = avctx->codec->init(avctx); if (ret < 0) { - if (avctx->priv_data) - free(avctx->priv_data); - avctx->priv_data = NULL; + av_freep(&avctx->priv_data); return ret; } return 0; @@ -144,8 +154,7 @@ int avcodec_close(AVCodecContext *avctx) { if (avctx->codec->close) avctx->codec->close(avctx); - free(avctx->priv_data); - avctx->priv_data = NULL; + av_freep(&avctx->priv_data); avctx->codec = NULL; return 0; } |