[Ffmpeg-devel] [PATCH] plain malloc in output_example.c

Ramiro Polla angustia
Sun Aug 20 20:51:24 CEST 2006


Michael Niedermayer wrote:
>> Unless I really missed something, the patch fixes all occurences of
>> malloc() in output_example.c. The executable file doesn't ever call the
>> system's malloc directly anymore.
>> Am I missing something?
> nope, sorry ...
> the original patch is ok if you add some note which says that the
> buffers passed into lav* can be allocated any way the user likes
> as long as they are aligned by enough for the architecture

In output_example.c, we have some calls to av_free in which the memory 
has been allocated internally by lav*, such as 
av_free(picture->data[0]); in line 400. So that memory has been 
allocated by av_malloc() (possibly with the memalign hack), and must 
therefore be freed by av_free().
Also, av_freep is used, which internally uses av_free. So that buffer 
must also have been allocated with av_malloc() to be correctly 
deallocated by av_free().

Wouldn't it be best to suggest that all memory fed to lav* in a program 
be allocated and freed by the av_{malloc,free}() functions? Otherwise, 
if the use chooses not to use av_{malloc,free}(), he would have to know 
which ones have been internally allocated, and use av_free() with them, 
and use whatever function he prefers for the buffers he has allocated 

Or is there a way, without ever using av_{malloc,free}(), that leaks no 
memory at all from lav* internally? (so that it isn't needed to call 
av_free() for picture->data[0], but only some freeing function for picture).

Ramiro Polla

More information about the ffmpeg-devel mailing list