mltframework / mlt

MLT Multimedia Framework
https://www.mltframework.org
GNU Lesser General Public License v2.1
1.5k stars 319 forks source link

Most basic example is full of memory leaks #193

Open alcinos opened 7 years ago

alcinos commented 7 years ago

Compiling and running this simplified version of src/examples/play.cpp (basically the same without a consumer):

#include <Mlt.h>
using namespace Mlt;

int main( int, char **argv )
{
        Factory::init( NULL );
        Profile profile;
        Producer producer( profile, argv[ 1 ] );
        return 0;
}

That code triggers a lot of leaks detected by valgrind:

==20206== HEAP SUMMARY:
==20206==     in use at exit: 469,516 bytes in 2,420 blocks
==20206==   total heap usage: 26,039 allocs, 23,619 frees, 8,148,403 bytes allocated
==20206== 
==20206== 0 bytes in 2 blocks are definitely lost in loss record 1 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x218F132C: ???
==20206==    by 0x218F0A4A: ???
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECE520: ??? (in /usr/lib/libdl-2.24.so)
==20206==    by 0x5ECDF81: dlopen (in /usr/lib/libdl-2.24.so)
==20206== 
==20206== 8 bytes in 1 blocks are definitely lost in loss record 13 of 423
==20206==    at 0x4C2AB8D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830B98: g_malloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1C47: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 8 bytes in 1 blocks are definitely lost in loss record 14 of 423
==20206==    at 0x4C2CC37: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1C85: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 8 bytes in 1 blocks are definitely lost in loss record 15 of 423
==20206==    at 0x4C2B1EC: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4E4A667: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 16 bytes in 1 blocks are possibly lost in loss record 100 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E2410: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F60: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C62AB: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0147: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206== 
==20206== 16 bytes in 1 blocks are possibly lost in loss record 101 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E22E0: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F60: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C62AB: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0147: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 16 bytes in 1 blocks are possibly lost in loss record 102 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E2410: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F60: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C6311: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0147: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206== 
==20206== 16 bytes in 1 blocks are possibly lost in loss record 103 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E22E0: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F60: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C6311: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0147: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 16 bytes in 1 blocks are possibly lost in loss record 104 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E2410: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F60: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198CF9D4: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0151: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206== 
==20206== 16 bytes in 1 blocks are possibly lost in loss record 105 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E22E0: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F60: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198CF9D4: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0151: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 16 bytes in 1 blocks are possibly lost in loss record 106 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E2410: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F60: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198CAB0B: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0156: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206== 
==20206== 16 bytes in 1 blocks are possibly lost in loss record 107 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E22E0: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F60: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198CAB0B: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0156: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 16 bytes in 2 blocks are definitely lost in loss record 108 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1CEF: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 32 bytes in 2 blocks are definitely lost in loss record 158 of 423
==20206==    at 0x4C2CC37: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1807: ???
==20206==    by 0x20CF1B95: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 32 bytes in 2 blocks are definitely lost in loss record 159 of 423
==20206==    at 0x4C2CC37: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1807: ???
==20206==    by 0x20CF1C9A: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 56 bytes in 7 blocks are definitely lost in loss record 222 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1D0F: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 56 bytes in 7 blocks are definitely lost in loss record 223 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1807: ???
==20206==    by 0x20CF1B95: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206== 
==20206== 64 bytes in 1 blocks are definitely lost in loss record 234 of 423
==20206==    at 0x4C2AB8D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4013FDB: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECE520: ??? (in /usr/lib/libdl-2.24.so)
==20206==    by 0x5ECDF81: dlopen (in /usr/lib/libdl-2.24.so)
==20206==    by 0x216EB8B3: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206== 
==20206== 80 bytes in 10 blocks are definitely lost in loss record 280 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1807: ???
==20206==    by 0x20CF1C9A: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206== 
==20206== 96 bytes in 1 blocks are possibly lost in loss record 338 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E1919: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E1A03: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C007A: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 96 bytes in 1 blocks are possibly lost in loss record 339 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E1919: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E1A03: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F52: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C62AB: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0147: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 96 bytes in 1 blocks are possibly lost in loss record 340 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E1919: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E1A03: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F52: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C6311: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0147: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 96 bytes in 1 blocks are possibly lost in loss record 341 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E1919: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E1A03: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F52: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198CF9D4: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0151: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 96 bytes in 1 blocks are possibly lost in loss record 342 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E1919: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E1A03: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6F52: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198CAB0B: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0156: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 128 bytes in 4 blocks are definitely lost in loss record 352 of 423
==20206==    at 0x4C2CC37: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1D0F: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 132 bytes in 1 blocks are possibly lost in loss record 354 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E2D3F: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6FB0: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C62AB: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0147: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206== 
==20206== 132 bytes in 1 blocks are possibly lost in loss record 355 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E2D3F: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6FB0: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C6311: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0147: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206== 
==20206== 148 bytes in 1 blocks are possibly lost in loss record 358 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E2B02: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6FB0: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198CF9D4: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0151: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206== 
==20206== 148 bytes in 1 blocks are possibly lost in loss record 359 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830BF0: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E2B02: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E6FB0: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198CAB0B: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C0156: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECDEE8: ??? (in /usr/lib/libdl-2.24.so)
==20206== 
==20206== 184 bytes in 1 blocks are possibly lost in loss record 365 of 423
==20206==    at 0x4C2CC37: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830C57: g_realloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x198E1897: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198E729C: g_type_register_static (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198D1659: g_param_type_register_static (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198D3983: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x198C015B: ??? (in /usr/lib/libgobject-2.0.so.0.5000.2)
==20206==    by 0x400F4F9: call_init.part.0 (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F60A: _dl_init (in /usr/lib/ld-2.24.so)
==20206==    by 0x4013B37: dl_open_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x40132D8: _dl_open (in /usr/lib/ld-2.24.so)
==20206== 
==20206== 416 bytes in 7 blocks are definitely lost in loss record 374 of 423
==20206==    at 0x4C2AB8D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4014BF3: _dl_close_worker (in /usr/lib/ld-2.24.so)
==20206==    by 0x401525D: _dl_close (in /usr/lib/ld-2.24.so)
==20206==    by 0x400F3A3: _dl_catch_error (in /usr/lib/ld-2.24.so)
==20206==    by 0x5ECE520: ??? (in /usr/lib/libdl-2.24.so)
==20206==    by 0x5ECDFDE: dlclose (in /usr/lib/libdl-2.24.so)
==20206==    by 0x216EB909: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 559 bytes in 1 blocks are definitely lost in loss record 383 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x814E3D2: ???
==20206==    by 0x815B8CF: ???
==20206==    by 0x8164AAB: ???
==20206==    by 0x7F349EB: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 684 bytes in 1 blocks are definitely lost in loss record 386 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x814E3D2: ???
==20206==    by 0x815B8CF: ???
==20206==    by 0x817FA4B: ???
==20206==    by 0x7F349EB: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 764 bytes in 24 blocks are definitely lost in loss record 387 of 423
==20206==    at 0x4C2AB8D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x5BAF189: strdup (in /usr/lib/libc-2.24.so)
==20206==    by 0x216EBA08: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 775 bytes in 1 blocks are definitely lost in loss record 388 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x814E3D2: ???
==20206==    by 0x815B8CF: ???
==20206==    by 0x8170A5B: ???
==20206==    by 0x7F349EB: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 938 (416 direct, 522 indirect) bytes in 12 blocks are definitely lost in loss record 390 of 423
==20206==    at 0x4C2AB8D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0xF830B98: g_malloc (in /usr/lib/libglib-2.0.so.0.5000.2)
==20206==    by 0x20CF1AFD: ???
==20206==    by 0x20CF1E19: ???
==20206==    by 0x20CF24C2: ???
==20206==    by 0x20CF267A: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 991 bytes in 1 blocks are definitely lost in loss record 391 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x814E3D2: ???
==20206==    by 0x815B8CF: ???
==20206==    by 0x81835BB: ???
==20206==    by 0x7F349EB: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 1,397 bytes in 1 blocks are definitely lost in loss record 396 of 423
==20206==    at 0x4C2AACE: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x4C2CC81: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x814E3D2: ???
==20206==    by 0x815B8CF: ???
==20206==    by 0x8163AAB: ???
==20206==    by 0x7F349EB: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 2,008 bytes in 64 blocks are definitely lost in loss record 399 of 423
==20206==    at 0x4C2AB8D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x5BAF189: strdup (in /usr/lib/libc-2.24.so)
==20206==    by 0x216EBA69: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 2,212 (32 direct, 2,180 indirect) bytes in 1 blocks are definitely lost in loss record 407 of 423
==20206==    at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x506C12F: mlt_properties_new (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x506EF5F: mlt_properties_load (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x20CF2628: ???
==20206==    by 0x20CEEDB7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== 5,196 bytes in 164 blocks are definitely lost in loss record 415 of 423
==20206==    at 0x4C2AB8D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20206==    by 0x5BAF189: strdup (in /usr/lib/libc-2.24.so)
==20206==    by 0x216EB9A7: ???
==20206==    by 0x507E008: mlt_repository_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x507D787: mlt_factory_init (in /usr/lib/libmlt.so.6.4.1)
==20206==    by 0x4E4A65A: Mlt::Factory::init(char const*) (in /usr/lib/libmlt++.so.6.4.1)
==20206==    by 0x4007FF: main (play.cpp:6)
==20206== 
==20206== LEAK SUMMARY:
==20206==    definitely lost: 13,726 bytes in 317 blocks
==20206==    indirectly lost: 2,702 bytes in 64 blocks
==20206==      possibly lost: 1,352 bytes in 18 blocks
==20206==    still reachable: 451,736 bytes in 2,021 blocks
==20206==                       of which reachable via heuristic:
==20206==                         newarray           : 1,536 bytes in 16 blocks
==20206==         suppressed: 0 bytes in 0 blocks

Since a decent amount of them come from the factory construction, I tried to get the pointer to the Mlt::Repository that is returned by Factory::init(), and delete it before the end, but that triggers a Segfault instead. Am I missing something?

ddennedy commented 7 years ago

Most of these appear to be leaks inside dependencies upon dlopen() of them. I am not very concerned about a one-time leak at time of init that will be cleaned up by the kernel at process exit. If you are, please try to investigate it as I am not. I am more concerned with continual leaks during usage that can be addressed in MLT's code. Some modules can have complex dependency graphs such as gtk2, qt, jackrack, and frei0r. I advise you to move all installed modules out of the way and test with one module at-a-time or with libmltcore.so plus whatever else.

I tried to get the pointer to the Mlt::Repository that is returned by Factory::init(), and delete it before the end, but that triggers a Segfault

mlt_factory_init() registers mlt_factory_close() with atexit(), and mlt_factory_close() calls mlt_repository_close(). So, yeah, don't delete that pointer.

alcinos commented 7 years ago

I modified the test code a bit:

#include <Mlt.h>
using namespace Mlt;

int main( int, char **argv )
{
    Factory::init( NULL );
    Profile profile;
    Producer producer(profile,"color", "red");
    producer.set("length", 20);
    producer.set("out", 19);
    return 0;
}

Valgrind seems to have problem when using dlopen, so I switched to clang's AddressSanitizer. It detects ODR violations, but I ignored them for now.

With no plugin available, only the Repository pointer leaks:

mlt_repository_init: no plugins found in "/home/nicolas/Documents/Developpement/Projets/mlt/install/lib/mlt"

=================================================================
==19310==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x5003a0 in operator new(unsigned long) (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x5003a0)
    #1 0x7f6921c0f6f0 in Mlt::Factory::init(char const*) /home/nicolas/Documents/Developpement/Projets/mlt/src/mlt++/MltFactory.cpp:32:9
    #2 0x7f6920731290 in __libc_start_main (/usr/lib/libc.so.6+0x20290)

SUMMARY: AddressSanitizer: 8 byte(s) leaked in 1 allocation(s).

I then tested the plugins one at a time:

Indirect leak of 888 byte(s) in 1 object(s) allocated from:

0 0x4c8980 in calloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8980)

#1 0x7f4ab93fb2a8 in mlt_properties_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:96:17
#2 0x7f4ab4eddd74  (<unknown module>)

Indirect leak of 400 byte(s) in 1 object(s) allocated from:

0 0x4c8ba0 in realloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8ba0)

#1 0x7f4ab940160a in mlt_properties_add /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:555:17

Indirect leak of 400 byte(s) in 1 object(s) allocated from:

0 0x4c8ba0 in realloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8ba0)

#1 0x7f4ab94015bc in mlt_properties_add /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:554:16

Indirect leak of 240 byte(s) in 2 object(s) allocated from:

0 0x4c8980 in calloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8980)

#1 0x7f4ab93f558f in mlt_property_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_property.c:92:22

Indirect leak of 43 byte(s) in 2 object(s) allocated from:

0 0x457060 in __strdup (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x457060)

#1 0x7f4ab940162f in mlt_properties_add /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:561:30

Indirect leak of 32 byte(s) in 1 object(s) allocated from:

0 0x4c8980 in calloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8980)

#1 0x7f4ab93fb34f in mlt_properties_new /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:118:24
#2 0x7f4ab4eddd74  (<unknown module>)

Indirect leak of 30 byte(s) in 1 object(s) allocated from:

0 0x457060 in __strdup (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x457060)

#1 0x7f4ab93f59b4 in mlt_property_set_string /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_property.c:204:24
#2 0x7f4ab93fb5be in load_properties /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:199:2
#3 0x7f4ab93fb49e in mlt_properties_load /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:260:3
#4 0x7f4ab4eddd74  (<unknown module>)

Indirect leak of 30 byte(s) in 1 object(s) allocated from:

0 0x457060 in __strdup (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x457060)

#1 0x7f4ab93f59b4 in mlt_property_set_string /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_property.c:204:24
#2 0x7f4ab93fb5d7 in load_properties /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:200:2
#3 0x7f4ab93fb49e in mlt_properties_load /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:260:3
#4 0x7f4ab4eddd74  (<unknown module>)

- libmltkdenlive: nothing more
- libmltlinsys: nothing more
- libmltmotion_est: nothing more
- libmltnormalize: nothing more
- libmltoldfilm: nothing more
- libmltopencv: nothing more
- libmltopengl: nothing more
- libmltplusgpl: nothing more
- libmltplus: nothing more
- libmltqt: nothing more
- libmltresample: nothing more
- libmltrtaudio: nothing more
- libmltsdl: nothing more
- libmltsox

Direct leak of 4406 byte(s) in 5 object(s) allocated from:

0 0x4c8ba0 in realloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8ba0)

#1 0x7f47dcc813d2  (<unknown module>)

Direct leak of 8 byte(s) in 1 object(s) allocated from:

0 0x4c8788 in __interceptor_malloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8788)

#1 0x7f47dbfc2788  (<unknown module>)

- libmltvidstab: nothing more
- libmltvideostab: nothing more
- libmltvfmx: nothing more
- libmltxine: nothing more
- libfrei0r :

Direct leak of 5264 byte(s) in 166 object(s) allocated from:

0 0x457060 in __strdup (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x457060)

#1 0x7f92943f3029  (<unknown module>)
#2 0x7f9298bae47a in mlt_repository_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_repository.c:114:5

Direct leak of 2008 byte(s) in 64 object(s) allocated from:

0 0x457060 in __strdup (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x457060)

#1 0x7f92943f2fe5  (<unknown module>)
#2 0x7f9298bae47a in mlt_repository_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_repository.c:114:5

Direct leak of 764 byte(s) in 24 object(s) allocated from:

0 0x457060 in __strdup (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x457060)

#1 0x7f92943f2f9a  (<unknown module>)
#2 0x7f9298bae47a in mlt_repository_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_repository.c:114:5

Direct leak of 32 byte(s) in 1 object(s) allocated from:

0 0x4c8980 in calloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8980)

#1 0x7f929890d34f in mlt_properties_new /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:118:24
#2 0x7f92943f2cdd  (<unknown module>)
#3 0x7f9298bae47a in mlt_repository_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_repository.c:114:5

Direct leak of 8 byte(s) in 1 object(s) allocated from:

0 0x5003a0 in operator new(unsigned long) (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x5003a0)

#1 0x7f9298b776f0 in Mlt::Factory::init(char const*) /home/nicolas/Documents/Developpement/Projets/mlt/src/mlt++/MltFactory.cpp:32:9
#2 0x7f9297699290 in __libc_start_main (/usr/lib/libc.so.6+0x20290)

Direct leak of 2 byte(s) in 2 object(s) allocated from:

0 0x4c8980 in calloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8980)

#1 0x7f92941ea32c  (<unknown module>)
#2 0x98df1004  (<unknown module>)

Indirect leak of 24768 byte(s) in 12 object(s) allocated from:

0 0x4c8980 in calloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8980)

#1 0x7f9293c6527f  (<unknown module>)

Indirect leak of 24768 byte(s) in 12 object(s) allocated from:

0 0x4c8980 in calloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8980)

#1 0x7f9293c6427f  (<unknown module>)

Indirect leak of 888 byte(s) in 1 object(s) allocated from:

0 0x4c8980 in calloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8980)

#1 0x7f929890d2a8 in mlt_properties_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:96:17
#2 0x7f92943f2cdd  (<unknown module>)
#3 0x7f9298bae47a in mlt_repository_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_repository.c:114:5

Indirect leak of 400 byte(s) in 1 object(s) allocated from:

0 0x4c8ba0 in realloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8ba0)

#1 0x7f92989135bc in mlt_properties_add /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:554:16

Indirect leak of 400 byte(s) in 1 object(s) allocated from:

0 0x4c8ba0 in realloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8ba0)

#1 0x7f929891360a in mlt_properties_add /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:555:17

Indirect leak of 240 byte(s) in 2 object(s) allocated from:

0 0x4c8980 in calloc (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x4c8980)

#1 0x7f929890758f in mlt_property_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_property.c:92:22

Indirect leak of 55 byte(s) in 2 object(s) allocated from:

0 0x457060 in __strdup (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x457060)

#1 0x7f929891362f in mlt_properties_add /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:561:30

Indirect leak of 34 byte(s) in 1 object(s) allocated from:

0 0x457060 in __strdup (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x457060)

#1 0x7f92989079b4 in mlt_property_set_string /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_property.c:204:24
#2 0x7f9298910499 in mlt_properties_parse_yaml /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:1761:3
#3 0x7f92943f2cdd  (<unknown module>)
#4 0x7f9298bae47a in mlt_repository_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_repository.c:114:5

Indirect leak of 34 byte(s) in 1 object(s) allocated from:

0 0x457060 in __strdup (/home/nicolas/Documents/Developpement/Projets/mlt/src/examples/play+0x457060)

#1 0x7f92989079b4 in mlt_property_set_string /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_property.c:204:24
#2 0x7f92989104b3 in mlt_properties_parse_yaml /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_properties.c:1762:3
#3 0x7f92943f2cdd  (<unknown module>)
#4 0x7f9298bae47a in mlt_repository_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_repository.c:114:5


So I think we see here some leaks that happen in the modules themselves, but I suspect that some of the leaks are mlt's fault. Specifically those that happen in mlt_property_set_string for example.

Other question, how can we prevent the Repository pointer from leaking?
ddennedy commented 7 years ago

how can we prevent the Repository pointer from leaking?

We can remove the call to mlt_repository_close() inside the destructor since that is done in Mlt::Factory::close(). It is done there because mlt_factory_init() creates the repository such that mlt_factory_close() should delete it. Some apps have no need for Mlt::Repository and need only call Mlt::Factory::init() and Mlt::Factory::close().

ddennedy commented 7 years ago

The change to Repository was made in commit a3188e301b5a9a1f25dbb98a510e366363348e64.

alcinos commented 7 years ago

This commit solves the problem when there is no plugin. I'll try to have a look at the other problems.

alcinos commented 7 years ago

For frei0r, one source of the leaks are the line looking registering the metadata

    MLT_REGISTER_METADATA( producer_type, pluginname, fill_param_info, strdup(name) );

(factory.c:461, 470 and 479) The strdup seems not to be freed, which is somewhat contradictory with the comment of mlt_repository_register_metadata:

 * IMPORTANT: mlt_repository will take responsibility for deallocating the metadata properties
 * that you supply!

What am I missing?

ddennedy commented 7 years ago

See commit a134539e. mlt_repository_register_metadata() used to take a mlt_properties that it would take ownership. That no longer happens directly but instead when mlt_repository_metadata() invokes the callback and handles the return pointer. As a result, the important note is confusing and needs to be relocated to the doxygen comment for mlt_metadata_callback.

As for frei0r, fill_param_info() frees the callback data (strdup(name)), but if that callback is never invoked, it leaks. The play.cpp example does not use Repository. The callback data comes from mlt_properties direntries inside factory.c:MLT_REPOSITORY{}, which is later closed inside that function. Hence, the reason for strdup(). Could use mlt_factory_register_for_clean_up() instead of mlt_properties_close() inside this block.

alcinos commented 7 years ago

The investigation goes on! I've tried to trackdown the leaks in libmltsox. The traceback is poor, I assume it is because of the dlopen step. So I tried to call mlt_register directly from mlt_repository_init. To do this, obviously I'm testing only one plugin, and I link it together with libmelt, so that there is exactly one function mlt_register than can be called.

This works as expected, the call to the mlt_register function seems to work exactly the same way (I see all the effects registered). But this time the LeakDetector doesn't catch anything... Any idea why this might happen?

ryno1234 commented 5 years ago

I'm having the same issue with the most basic example as well, but I'm using a C# / SWIG wrapper. Below is the code I'm using which very closely replicates the core of @alcinos example with some extra to track memory and iterate over the video generation.

    public void RunTest()
    {
        Mlt.Factory.init(Helpers.GetRelativeRepoDir());

        var mltProfile = new Mlt.Profile();

        CaptureMemoryStats();

        for (int testIteration = 1; testIteration <= 10; testIteration++)
        {
            Console.WriteLine("Test #" + testIteration);

            var producer = new Mlt.Producer(mltProfile, "color", "red");
            producer.set("length", 20);
            producer.set("out", 19);

            var consumer = new Mlt.Consumer(mltProfile, $"avformat:c:\\temp.avi");

            consumer.connect_producer(producer);

            producer.Dispose();

            consumer.start();

            while (true)
            {
                if (consumer.is_stopped())
                    break;
            }

            consumer.Dispose();

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            CaptureMemoryStats();
            PrintMemoryStats();

            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
        }

        Mlt.Factory.close();

        Console.WriteLine("DONE!");
        Console.WriteLine("Press return to exit...");
        Console.ReadLine();
    }

    private Dictionary<string, List<long>> _memoryStats = null;
    private Dictionary<string, List<long>> GetMemoryStats()
    {
        var process = System.Diagnostics.Process.GetCurrentProcess();

        if (_memoryStats == null)
        {
            _memoryStats = new Dictionary<string, List<long>>();
            _memoryStats[nameof(process.HandleCount)] = new List<long>();
            _memoryStats[nameof(process.NonpagedSystemMemorySize64)] = new List<long>();
            _memoryStats[nameof(process.PagedMemorySize64)] = new List<long>();
            _memoryStats[nameof(process.PeakPagedMemorySize64)] = new List<long>();
            _memoryStats[nameof(process.PrivateMemorySize64)] = new List<long>();
            _memoryStats[nameof(process.VirtualMemorySize64)] = new List<long>();
            _memoryStats[nameof(process.WorkingSet64)] = new List<long>();
        }

        return _memoryStats;
    }

    private void CaptureMemoryStats()
    {
        var memoryStats = GetMemoryStats();
        var currentProcess = Process.GetCurrentProcess();
        memoryStats[nameof(currentProcess.HandleCount)].Add(currentProcess.HandleCount);
        memoryStats[nameof(currentProcess.NonpagedSystemMemorySize64)].Add(currentProcess.NonpagedSystemMemorySize64);
        memoryStats[nameof(currentProcess.PagedMemorySize64)].Add(currentProcess.PagedMemorySize64);
        memoryStats[nameof(currentProcess.PeakPagedMemorySize64)].Add(currentProcess.PeakPagedMemorySize64);
        memoryStats[nameof(currentProcess.PrivateMemorySize64)].Add(currentProcess.PrivateMemorySize64);
        memoryStats[nameof(currentProcess.VirtualMemorySize64)].Add(currentProcess.VirtualMemorySize64);
        memoryStats[nameof(currentProcess.WorkingSet64)].Add(currentProcess.WorkingSet64);
    }

    private void PrintMemoryStats()
    {
        var memoryStats = GetMemoryStats();

        Console.WriteLine();
        Console.WriteLine();
        Console.WriteLine();
        Console.WriteLine("---------------------------------------------------");
        Console.WriteLine("MEMORY SUMMARY");
        Console.WriteLine("---------------------------------------------------");
        Console.WriteLine();

        List<int> columnLengths = new List<int>();

        // Key name max length
        columnLengths.Add(memoryStats.Keys.Max(o => o.Length));

        int samples = memoryStats.First().Value.Count;

        for (int i = 1; i <= samples; i++)
        {
            columnLengths.Add(memoryStats.Max(kvp => kvp.Value[i - 1].ToString("N0").Length));
        }

        foreach (var key in memoryStats.Keys)
        {
            // Column 1
            Console.Write(key.PadRight(columnLengths[0]));

            for (int i = 1; i <= samples; i++)
            {
                string columnVal = memoryStats[key][i - 1].ToString("N0");
                Console.Write(columnVal.PadLeft(columnLengths[i] + 1));
            }
            Console.WriteLine("");
        }

        Console.WriteLine("");
        Console.WriteLine("");
    }

The following is a screenshot of the memory usage at the baseline (blue box prior to running any MLT-related code) and after iterations 1 - 6.

Memory snapshot

The following is a suspect stack trace acquired from a full memory dump. After each iteration of my test there is a new thread with this same stack trace.

Unreleased threads

Any idea why this may be happening? We cannot realistically take our application into production until we can get the memory under control.

Thank you.

ryno1234 commented 5 years ago

I should note that my above example does not leak memory when the consumer is "xml".

ddennedy commented 5 years ago

@ryno1234 You might be observing some side effects of memory pooling in mlt_pool. Not saying that is the only culprit, but it is going to affect tests like yours. You can compile MLT with -DUSE_MLT_POOL=0 to turn it off. Another consumer that consumes media without using avformat is null. I am not setup to run your kind of tests (C# bindings) to help look into this that way.

ryno1234 commented 5 years ago

@ddennedy, you mentioned that mlt_pool would affect tests like mine. Your comment suggests to me that there is a different intended usage of MLT to generate back to back output files. Is the intention to initialize the factory and close it after each iteration of generating a file? What change would be required to ensure mlt_pool wasn't affecting us like this?

I will be compiling MLT with -DUSE_MLT_POOL=0 and see if that helps.

Thank you for your quick response by the way. This is my primary focus at the moment and your input is really appreciated.

UPDATE

-DUSE_MLT_POOL=0 didn't help the memory usage increasing after each iteration. I also confirmed that the flag was set correctly and the correct DLLs are being used by attaching a debugger to ensure that we're skipping the MLT pool code. No-dice.

Any other suggestions on either detecting the leak and / or approaching the task of multiple generation executions back to back? I would think this would be something that would affect pretty much any user.

ryno1234 commented 5 years ago

Looks like we may be leaking threads. In the screenshot below (consumer_read_ahead_thread()) the thread created will stay stuck at this line once it has completed all of its work blocking, for what seems like, indefinitely. The blocking remains even after the consumer has completed its work and all objects are disposed. Upon each new video generation iteration, a new thread is created and ultimately gets stuck at the same blocking call creating a pileup of threads.

Shouldn't this thread be freed once done with its work? I haven't deciphered the code entirely here, but I do see that near the bottom of consumer_read_ahead_thread there are function calls that clean up the mutex, queue, etc.

Thread stuck

ddennedy commented 5 years ago

You are not calling consumer.stop(), and I know this is not obviously necessary because 1) you would expect a destructor to do it if needed and 2) is_stopped() returned true. mlt_consumer_stop() calls consumer_read_ahead_stop() which signals the pthread condition var that your thread is waiting on. There is a commented out call to mlt_consumer_stop() inside of mlt_consumer_close() (the C destructor). From the git blame, I can see this was originally commented-out in 2005. Then, in 2012 I uncommented it along with adding a check at the top of mlt_consumer_stop() to return if already stopped. However, it was soon reverted (by me). I do not recall exactly all the reasons, but I can tell you this: there are two forms of stop state. One is the state of the threads inside the base mlt_consumer. The other is determined by the consumer implementation's is_stopped() virtual function. mlt_consumer_is_stopped() and Mlt::Consumer::is_stopped() are the latter. There can be some improvement here, but all MLT users have gotten by calling stop().

I should mention that if you test using the null consumer set property terminate_on_pause=1 to have proper end-of-stream handling; otherwise, it spins forever on the last frame.

Regarding back-to-back execution architecture, many applications serialize to XML and then process that with melt in a child process to provide process isolation and to facilitate troubleshooting by having a job XML on record.

ryno1234 commented 5 years ago

@ddennedy, your comment is solid-gold sir. This helps immensely.

Calling mlt_consumer_stop(), or in my case consumer.stop(); fixed my memory leak in my most basic test scenario. I will test with more complex situations later today.

Do you want me to open up a new issue to track regarding the is_stopped/stop functionality or do you intend to leave it as is? For now, I will explicitly call stop.

ddennedy commented 5 years ago

Yes please file that separate issue about stop.