Hi, there.

There is a large memory leak issue (> 200 mb) in CreateDescriptorFromStream, Ap4DescriptorFactory.cpp:127 in the newest branch 5922ba762af46.

To reproduce it, run
~~~~
mp42aac poc /dev/null
~~~~

POC:

[poc.zip](https://github.com/axiomatic-systems/Bento4/files/7005325/mp42aac-leak-CreateDescriptorFromStream127.zip)
(unzip first)

Here is the reproduce trace reported by Valgrind:
~~~~
==130483== Memcheck, a memory error detector
==130483== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==130483== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==130483== 
Audio Track:
  duration: 15000 ms
  sample count: 750
==130483== 
==130483== HEAP SUMMARY:
==130483==     in use at exit: 203,423,672 bytes in 2 blocks
==130483==   total heap usage: 324 allocs, 322 frees, 203,525,969 bytes allocated
==130483== 
==130483== 56 bytes in 1 blocks are definitely lost in loss record 1 of 2
==130483==    at 0x4C2E216: operator new(unsigned long) (vg_replace_malloc.c:334)
==130483==    by 0x4496F3: AP4_DescriptorFactory::CreateDescriptorFromStream(AP4_ByteStream&, AP4_Descriptor*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x44BE4D: AP4_EsdsAtom::AP4_EsdsAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x44BD28: AP4_EsdsAtom::Create(unsigned int, AP4_ByteStream&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42D60C: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42C335: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x43F629: AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x412730: AP4_SampleEntry::Read(AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x41337E: AP4_AudioSampleEntry::AP4_AudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x413DE0: AP4_MpegAudioSampleEntry::AP4_MpegAudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x4146F7: AP4_Mp4aSampleEntry::AP4_Mp4aSampleEntry(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42C6FD: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483== 
==130483== 203,423,616 bytes in 1 blocks are possibly lost in loss record 2 of 2
==130483==    at 0x4C2E8BB: operator new[](unsigned long) (vg_replace_malloc.c:423)
==130483==    by 0x404510: AP4_DataBuffer::ReallocateBuffer(unsigned int) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x4043C5: AP4_DataBuffer::SetDataSize(unsigned int) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x449271: AP4_UnknownDescriptor::AP4_UnknownDescriptor(AP4_ByteStream&, unsigned char, unsigned int, unsigned int) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x449715: AP4_DescriptorFactory::CreateDescriptorFromStream(AP4_ByteStream&, AP4_Descriptor*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x44BE4D: AP4_EsdsAtom::AP4_EsdsAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x44BD28: AP4_EsdsAtom::Create(unsigned int, AP4_ByteStream&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42D60C: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42C335: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x43F629: AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x412730: AP4_SampleEntry::Read(AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x41337E: AP4_AudioSampleEntry::AP4_AudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483== 
==130483== LEAK SUMMARY:
==130483==    definitely lost: 56 bytes in 1 blocks
==130483==    indirectly lost: 0 bytes in 0 blocks
==130483==      possibly lost: 203,423,616 bytes in 1 blocks
==130483==    still reachable: 0 bytes in 0 blocks
==130483==         suppressed: 0 bytes in 0 blocks
==130483== 
==130483== For counts of detected and suppressed errors, rerun with: -v
==130483== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
~~~~
Memory leak in CreateDescriptorFromStream, Ap4DescriptorFactory.cpp:127
This is a GitHub Issue
repo:Bento4
owner:axiomatic-systems
Title : Memory leak in CreateDescriptorFromStream, Ap4DescriptorFactory.cpp:127
Issue date:

--- start body ---
Hi, there.

There is a large memory leak issue (> 200 mb) in CreateDescriptorFromStream, Ap4DescriptorFactory.cpp:127 in the newest branch 5922ba762af46.

To reproduce it, run
~~~~
mp42aac poc /dev/null
~~~~

POC:

[poc.zip](https://github.com/axiomatic-systems/Bento4/files/7005325/mp42aac-leak-CreateDescriptorFromStream127.zip)
(unzip first)

Here is the reproduce trace reported by Valgrind:
~~~~
==130483== Memcheck, a memory error detector
==130483== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==130483== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==130483== 
Audio Track:
  duration: 15000 ms
  sample count: 750
==130483== 
==130483== HEAP SUMMARY:
==130483==     in use at exit: 203,423,672 bytes in 2 blocks
==130483==   total heap usage: 324 allocs, 322 frees, 203,525,969 bytes allocated
==130483== 
==130483== 56 bytes in 1 blocks are definitely lost in loss record 1 of 2
==130483==    at 0x4C2E216: operator new(unsigned long) (vg_replace_malloc.c:334)
==130483==    by 0x4496F3: AP4_DescriptorFactory::CreateDescriptorFromStream(AP4_ByteStream&, AP4_Descriptor*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x44BE4D: AP4_EsdsAtom::AP4_EsdsAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x44BD28: AP4_EsdsAtom::Create(unsigned int, AP4_ByteStream&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42D60C: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42C335: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x43F629: AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x412730: AP4_SampleEntry::Read(AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x41337E: AP4_AudioSampleEntry::AP4_AudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x413DE0: AP4_MpegAudioSampleEntry::AP4_MpegAudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x4146F7: AP4_Mp4aSampleEntry::AP4_Mp4aSampleEntry(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42C6FD: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483== 
==130483== 203,423,616 bytes in 1 blocks are possibly lost in loss record 2 of 2
==130483==    at 0x4C2E8BB: operator new[](unsigned long) (vg_replace_malloc.c:423)
==130483==    by 0x404510: AP4_DataBuffer::ReallocateBuffer(unsigned int) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x4043C5: AP4_DataBuffer::SetDataSize(unsigned int) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x449271: AP4_UnknownDescriptor::AP4_UnknownDescriptor(AP4_ByteStream&, unsigned char, unsigned int, unsigned int) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x449715: AP4_DescriptorFactory::CreateDescriptorFromStream(AP4_ByteStream&, AP4_Descriptor*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x44BE4D: AP4_EsdsAtom::AP4_EsdsAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x44BD28: AP4_EsdsAtom::Create(unsigned int, AP4_ByteStream&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42D60C: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x42C335: AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x43F629: AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x412730: AP4_SampleEntry::Read(AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483==    by 0x41337E: AP4_AudioSampleEntry::AP4_AudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) (in /mnt/data/playground/Bento4/build-o/mp42aac)
==130483== 
==130483== LEAK SUMMARY:
==130483==    definitely lost: 56 bytes in 1 blocks
==130483==    indirectly lost: 0 bytes in 0 blocks
==130483==      possibly lost: 203,423,616 bytes in 1 blocks
==130483==    still reachable: 0 bytes in 0 blocks
==130483==         suppressed: 0 bytes in 0 blocks
==130483== 
==130483== For counts of detected and suppressed errors, rerun with: -v
==130483== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
~~~~
--- end body ---
