isobmff icon indicating copy to clipboard operation
isobmff copied to clipboard

Report Memory leak

Open ohjiwoo123 opened this issue 2 years ago • 2 comments

If I make just movie box and release the movie box. there is memory leak (still reachable) in Mp4NewMovieExt

memory leak test with valgrind below

valgrind --leak-check=full --error-limit=no execute_filename

image

And also There is a Memory Leak in sample Entry Handler for AVC1 (or avc1 atom).
I think that If I try MP4AddMediaSamples , there is memory leak in sample Entry Handler for AVC1(or avc1 atom).
I Call MP4AddMediaSamples 4times in this program and 128 bytes four blocks (each 32bytes)

==120327==
==120327== HEAP SUMMARY:
==120327==     in use at exit: 430 bytes in 10 blocks
==120327==   total heap usage: 1,090 allocs, 1,080 frees, 22,674,917 bytes allocated
==120327==
==120327== 36 (32 direct, 4 indirect) bytes in 1 blocks are definitely lost in loss record 3 of 10
==120327==    at 0x4C2BF79: calloc (vg_replace_malloc.c:762)
==120327==    by 0x41CB2F: MP4NewHandle (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x44E682: createFromInputStream (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419A03: MP4ParseAtomUsingProtoList (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419C33: MP4ParseAtom (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x44FD20: createFromInputStream (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419A03: MP4ParseAtomUsingProtoList (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x4749E7: addSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x470EE3: addSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x421E46: MP4AddMediaSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x407064: muxer::isobmff::CMuxer::SetAvcSampleDescription(muxer::isobmff::VideoStreamInfo, muxer::isobmff::CMuxer::TrackMedia&, std::string&) (muxer.cpp:531)
==120327==    by 0x405BBB: muxer::isobmff::CMuxer::AddTrack(muxer::isobmff::TrackInfo, unsigned int&, std::string&) (muxer.cpp:163)
==120327==
==120327== 36 (32 direct, 4 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 10
==120327==    at 0x4C2BF79: calloc (vg_replace_malloc.c:762)
==120327==    by 0x41CB2F: MP4NewHandle (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x44E682: createFromInputStream (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419A03: MP4ParseAtomUsingProtoList (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419C33: MP4ParseAtom (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x44FD20: createFromInputStream (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419A03: MP4ParseAtomUsingProtoList (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x4749E7: addSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x470EE3: addSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x421E46: MP4AddMediaSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x407064: muxer::isobmff::CMuxer::SetAvcSampleDescription(muxer::isobmff::VideoStreamInfo, muxer::isobmff::CMuxer::TrackMedia&, std::string&) (muxer.cpp:531)
==120327==    by 0x405D95: muxer::isobmff::CMuxer::AddTrack(muxer::isobmff::TrackInfo, unsigned int&, std::string&) (muxer.cpp:176)
==120327==
==120327== 71 (32 direct, 39 indirect) bytes in 1 blocks are definitely lost in loss record 7 of 10
==120327==    at 0x4C2BF79: calloc (vg_replace_malloc.c:762)
==120327==    by 0x41CB2F: MP4NewHandle (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x44E56C: createFromInputStream (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419A03: MP4ParseAtomUsingProtoList (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419C33: MP4ParseAtom (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x44FD20: createFromInputStream (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419A03: MP4ParseAtomUsingProtoList (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x4749E7: addSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x470EE3: addSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x421E46: MP4AddMediaSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x407064: muxer::isobmff::CMuxer::SetAvcSampleDescription(muxer::isobmff::VideoStreamInfo, muxer::isobmff::CMuxer::TrackMedia&, std::string&) (muxer.cpp:531)
==120327==    by 0x405BBB: muxer::isobmff::CMuxer::AddTrack(muxer::isobmff::TrackInfo, unsigned int&, std::string&) (muxer.cpp:163)
==120327==
==120327== 71 (32 direct, 39 indirect) bytes in 1 blocks are definitely lost in loss record 8 of 10
==120327==    at 0x4C2BF79: calloc (vg_replace_malloc.c:762)
==120327==    by 0x41CB2F: MP4NewHandle (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x44E56C: createFromInputStream (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419A03: MP4ParseAtomUsingProtoList (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419C33: MP4ParseAtom (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x44FD20: createFromInputStream (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x419A03: MP4ParseAtomUsingProtoList (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x4749E7: addSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x470EE3: addSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x421E46: MP4AddMediaSamples (in /home/jwoh/mediastreamingserver/src/module/muxer/isobmff/example/build/muxer_tests)
==120327==    by 0x407064: muxer::isobmff::CMuxer::SetAvcSampleDescription(muxer::isobmff::VideoStreamInfo, muxer::isobmff::CMuxer::TrackMedia&, std::string&) (muxer.cpp:531)
==120327==    by 0x405D95: muxer::isobmff::CMuxer::AddTrack(muxer::isobmff::TrackInfo, unsigned int&, std::string&) (muxer.cpp:176)
==120327==
==120327== LEAK SUMMARY:
==120327==    definitely lost: 128 bytes in 4 blocks
==120327==    indirectly lost: 86 bytes in 4 blocks
==120327==      possibly lost: 0 bytes in 0 blocks
==120327==    still reachable: 216 bytes in 2 blocks
==120327==         suppressed: 0 bytes in 0 blocks
==120327== Reachable blocks (those to which a pointer was found) are not shown.
==120327== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==120327==
==120327== For counts of detected and suppressed errors, rerun with: -v
==120327== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)

Additionally, I guess that below atoms have memory leak.

atom type : avc1 
atom name : visual sample entry

atom type : avcC
atom name : VCConfig

**VCConfig.c** **259 line**
err = self->super->createFromInputStream(s, proto, (char *)inputStream);

**VisualSampleEntryAtom.c** **91 line**
err = self->super->createFromInputStream(s, proto, (char *)inputStream);

I am gonna choose other library due to some memory leak of this lib.
But, I still want to contribute for this library.

ohjiwoo123 avatar Dec 25 '23 10:12 ohjiwoo123

Thanks @ohjiwoo123 for the valuable feedback. Note this repository is the reference software that is not really deployed with efficiency in mind. The main goal is to show how certain tools operate.

It's very hard to find contributors to this repository because there are many other implementations out there that are more efficient. There is also no mandate at MPEG that requires people to implement their proposed technologies in this repository (unfortunately). I personally try to contribute from time to time things that Apple was proposing to ISOBMFF family of standards. I really appreciate your input and will try to find time to merge your PRs, especially now because we are about to finish the 2nd edition of 14496-32. So any feedback is valuable here. Thank you.

The ultimate goal would be to combine this software with https://github.com/MPEGGroup/FileFormatConformance. But its really hard to find time to do this work.

podborski avatar Feb 15 '24 01:02 podborski

I understand what you said. Thank you for your efforts for the betterment of the public. Using this library has been a great help in understanding the isobmff format. I am currently using a different library. thank you

ohjiwoo123 avatar Feb 15 '24 03:02 ohjiwoo123