What is the difference between av_free() and av_freep() in FFmpeg?

In FFmpeg, both av_free() and av_freep() are used for freeing memory, but there are some differences between them.

  1. The av_free() function is used to release memory allocated by av_malloc(), av_mallocz(), av_calloc() or av_realloc(). It takes a pointer to the memory block to be released as an input parameter and sets that pointer to NULL to prevent misuse of the freed memory.

Example Usage:

uint8_t* buffer = av_malloc(1024);
...
av_free(buffer);
buffer = NULL;
  1. av_freep() releases memory by setting the pointer to NULL. Unlike av_free(), it does not require passing a pointer to the pointer, but accepts the pointer directly as the input parameter.

Example usage:

uint8_t* buffer = av_malloc(1024);
...
av_freep(&buffer);

In summary, when you have a pointer to a pointer, you can use the av_freep() function to free memory. Otherwise, you can use the av_free() function to free memory and set the pointer to NULL.

bannerAds