[vlc-devel] Memory leak help

Richard Hosking richard at hovis.net
Mon Nov 26 16:20:02 CET 2007


I am trying to investigate a memory leak I am seeing when using udp
on Linux with the latest trunk.

vlc udp://@236.1.1.7:11117 --sout '#standard{access=udp,mux=ts,dst=224.0.1.66:11666}'

So far I have traced this down to the block_Realloc call in
modules/access/udp.c.

If I replace block_Realloc with the following as a test....

     block_t *p_new_block;
     p_new_block = block_New( p_access, p_block->i_buffer );
     memcpy( p_new_block->p_buffer, p_block->p_buffer, p_block->i_buffer );
     block_Release( p_block );
     return p_new_block;

The memory leak goes away.

I cannot determine why block_Realloc is leaking memory.  In my case the
original p_block buffer size is 65535 and the new size is 1316.

Looking at the source for block_Realloc in src/misc/block.c, both of
the following 'if' blocks are true in my case and the function returns
immediately afterwards as i_prebody and i_body are set to 0.

     if( p_block->p_buffer - i_prebody > p_block->p_sys->p_allocated_buffer &&
         p_block->p_buffer - i_prebody < p_block->p_sys->p_allocated_buffer +
         p_block->p_sys->i_allocated_buffer )
     {
         p_block->p_buffer -= i_prebody;
         p_block->i_buffer += i_prebody;
         i_prebody = 0;
     }
     if( p_block->p_buffer + i_body < p_block->p_sys->p_allocated_buffer +
         p_block->p_sys->i_allocated_buffer )
     {
         p_block->i_buffer = i_buffer_size;
         i_body = 0;
     }

Could these buffer manipulations be causing a leak later on when the
block is released or adjusted again? Any ideas which I could try?

Richard.



More information about the vlc-devel mailing list