# HG changeset patch # User glantau # Date 1021762790 0 # Node ID e2cb8a4ee0c52c93c293127ac6fddf7ce1a34297 # Parent bf164fce2c14cffa87d9bc669ba7926c434ee461 proper memory handling functions diff -r bf164fce2c14 -r e2cb8a4ee0c5 utils.c --- a/utils.c Sat May 18 22:59:12 2002 +0000 +++ b/utils.c Sat May 18 22:59:50 2002 +0000 @@ -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 -#include -#include -#include "common.h" +#include "avcodec.h" #include "dsputil.h" -#include "avcodec.h" #include "mpegvideo.h" #ifdef HAVE_MALLOC_H #include -#else -#include #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 @@ 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 @@ } 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 @@ { 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; }