[FFmpeg-devel] Memory leak in rtmp_open()

Andrey Myznikov andrey.myznikov at gmail.com
Tue Jan 14 01:31:24 CET 2014

On 01/13/2014 11:56 PM, Michael Niedermayer wrote:
> On Mon, Jan 13, 2014 at 02:13:48PM +0200, Andrey Myznikov wrote:
>> Hello all,
>>      attached is little path to libavformat/librtmp.c fixes potential
>> memory and socket loss in rtmp_open().
>> The reason is that RTMP_ConnectStream() does not call to
>> RTMP_Close() on error.
>> Observed actually with trial version of Adobe Flash Media Server
>> limiting number of simultaneous connections.
> its not safe to call RTMP_Close() on the fail: path ?
> iam asking as this would be simpler
> [...]

RTMP_Close() may free() some NULL pointers in "r" structure if 
RTMP_Connect() was not successfull,
but according to
     $ man 3 free
"If |ptr| is a null pointer, no action occurs".

Therefore  you are right - it should be safe, after adding a check for 
rc value:
if ( rc != 0 ) {

More information about the ffmpeg-devel mailing list