Skip to content

Instantly share code, notes, and snippets.

@rikaardhosein
Created April 22, 2012 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikaardhosein/2466747 to your computer and use it in GitHub Desktop.
Save rikaardhosein/2466747 to your computer and use it in GitHub Desktop.
libavutil's av_malloc
void *av_malloc(size_t size)
{
void *ptr = NULL;
#if CONFIG_MEMALIGN_HACK
long diff;
#endif
/* let's disallow possible ambiguous cases */
if (size > (max_alloc_size-32))
return NULL;
#if CONFIG_MEMALIGN_HACK
ptr = malloc(size+ALIGN);
if(!ptr)
return ptr;
diff= ((-(long)ptr - 1)&(ALIGN-1)) + 1;
ptr = (char*)ptr + diff;
((char*)ptr)[-1]= diff;
#elif HAVE_POSIX_MEMALIGN
if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation
if (posix_memalign(&ptr,ALIGN,size))
ptr = NULL;
#elif HAVE_MEMALIGN
ptr = memalign(ALIGN,size);
#else
ptr = malloc(size);
#endif
if(!ptr && !size)
ptr= av_malloc(1);
return ptr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment