Opened 5 years ago

Closed 5 years ago

#4049 closed defect (fixed)

av_write_trailer() - memory leaks on error - interleave_packet()

Reported by: perexg Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: leak
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

The av_write_trails() function calls s->oformat->write_trailer() callback only when interleave_packet() does not return an error.

In other case (storage is full, output file descriptor is unavailable), the callback is not called, causing memory leaks, because muxers are freeing their structures in the .write_trailer() callback

Attachments (1)

patchmuxleak.diff (481 bytes) - added by cehoyos 5 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 5 years ago by cehoyos

  • Keywords leak added
  • Priority changed from important to normal

Please provide valgrind output when reporting a memory leak.

comment:2 Changed 5 years ago by perexg

==17815== 11,720 bytes in 4 blocks are definitely lost in loss record 41 of 42
==17815==    at 0x4C29D96: memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==17815==    by 0x4C29E87: posix_memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==17815==    by 0x548CA1: av_mallocz (mem.c:95)
==17815==    by 0x570C2D: mpegts_write_header (mpegtsenc.c:661)
==17815==    by 0x57476C: avformat_write_header (mux.c:419)
=17815== 7,700 (2,960 direct, 4,740 indirect) bytes in 2 blocks are definitely lost in loss record 40 of 42
==17815==    at 0x4C29D96: memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==17815==    by 0x4C29E87: posix_memalign (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==17815==    by 0x5489B9: av_malloc (mem.c:95)
==17815==    by 0x575CEA: avformat_alloc_context (options.c:110)
==17815==    by 0x570F68: mpegts_write_header (mpegtsenc.c:705)
==17815==    by 0x57476C: avformat_write_header (mux.c:419)

etc.. this is after av_write_trailer() call... but the write callback returned error before, because fd was closed (by remote side)..

Anyway, the summary description should be enough to check this problem.

Changed 5 years ago by cehoyos

comment:3 Changed 5 years ago by cehoyos

  • Status changed from new to open
  • Version changed from unspecified to git-master

Could you test if attached untested patch changes anything?

comment:4 Changed 5 years ago by michael

the patch looks good, please use ret >= 0 instead of ret == 0 though

comment:5 Changed 5 years ago by cehoyos

  • Resolution set to fixed
  • Status changed from open to closed

Should be fixed in 25ccf5df

Note: See TracTickets for help on using tickets.