## Environment 
Ubuntu 22.04.3 LTS 
## Compiler 
clang version 11.0.0 
Target: x86_64-unknown-linux-gnu 
Thread model: posix 
## Affected Version
Bento4 v1.6.0-641
## Step to reproduce 
```
pushd Bento4
mkdir bld
pushd bld
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="-fsanitize=address -fno-inline" ..
make -j4

./mp42aac <PoCfile> /dev/null
```
## Contents of PoCfile 
```
Unzip the file below.
```
[PoC.zip](https://github.com/axiomatic-systems/Bento4/files/14081824/PoC.zip)
## Expected behavior 
Print error or warning messages handled within mp42aac. 
## Current behavior 
```
==1184923==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x4fa217 in operator new(unsigned long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:99:3
    #1 0x63c025 in AP4_DescriptorFactory::CreateDescriptorFromStream(AP4_ByteStream&, AP4_Descriptor*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4DescriptorFactory.cpp:98:26
    #2 0x6481e6 in AP4_EsdsAtom::AP4_EsdsAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4EsdsAtom.cpp:76:9
    #3 0x647e25 in AP4_EsdsAtom::Create(unsigned int, AP4_ByteStream&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4EsdsAtom.cpp:52:16
    #4 0x5bfeae in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:508:20
    #5 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #6 0x607ad4 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #7 0x5439d3 in AP4_AudioSampleEntry::AP4_AudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4SampleEntry.cpp:420:5
    #8 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #9 0x552854 in AP4_StsdAtom::AP4_StsdAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4StsdAtom.cpp:101:13
    #10 0x551bc2 in AP4_StsdAtom::Create(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4StsdAtom.cpp:57:16
    #11 0x5bf8d0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:458:20
    #12 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #13 0x607ad4 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #14 0x607868 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:139:5
    #15 0x5bf3ec in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:816:20
    #16 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #17 0x607bd3 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #18 0x607868 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:139:5
    #19 0x5bf3ec in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:816:20
    #20 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #21 0x607bd3 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #22 0x607868 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:139:5
    #23 0x5bf3ec in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:816:20
    #24 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #25 0x607bd3 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #26 0x607868 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:139:5

SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).
```
Memory leaks in Ap4DescriptorFactory.cpp:98
This is a GitHub Issue
repo:Bento4
owner:axiomatic-systems
Title : Memory leaks in Ap4DescriptorFactory.cpp:98
Issue date:

--- start body ---
## Environment 
Ubuntu 22.04.3 LTS 
## Compiler 
clang version 11.0.0 
Target: x86_64-unknown-linux-gnu 
Thread model: posix 
## Affected Version
Bento4 v1.6.0-641
## Step to reproduce 
```
pushd Bento4
mkdir bld
pushd bld
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="-fsanitize=address -fno-inline" ..
make -j4

./mp42aac <PoCfile> /dev/null
```
## Contents of PoCfile 
```
Unzip the file below.
```
[PoC.zip](https://github.com/axiomatic-systems/Bento4/files/14081824/PoC.zip)
## Expected behavior 
Print error or warning messages handled within mp42aac. 
## Current behavior 
```
==1184923==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x4fa217 in operator new(unsigned long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:99:3
    #1 0x63c025 in AP4_DescriptorFactory::CreateDescriptorFromStream(AP4_ByteStream&, AP4_Descriptor*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4DescriptorFactory.cpp:98:26
    #2 0x6481e6 in AP4_EsdsAtom::AP4_EsdsAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4EsdsAtom.cpp:76:9
    #3 0x647e25 in AP4_EsdsAtom::Create(unsigned int, AP4_ByteStream&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4EsdsAtom.cpp:52:16
    #4 0x5bfeae in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:508:20
    #5 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #6 0x607ad4 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #7 0x5439d3 in AP4_AudioSampleEntry::AP4_AudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4SampleEntry.cpp:420:5
    #8 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #9 0x552854 in AP4_StsdAtom::AP4_StsdAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4StsdAtom.cpp:101:13
    #10 0x551bc2 in AP4_StsdAtom::Create(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4StsdAtom.cpp:57:16
    #11 0x5bf8d0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:458:20
    #12 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #13 0x607ad4 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #14 0x607868 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:139:5
    #15 0x5bf3ec in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:816:20
    #16 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #17 0x607bd3 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #18 0x607868 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:139:5
    #19 0x5bf3ec in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:816:20
    #20 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #21 0x607bd3 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #22 0x607868 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:139:5
    #23 0x5bf3ec in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:816:20
    #24 0x5bbc50 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #25 0x607bd3 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:194:12
    #26 0x607868 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/SLICER/Google_testsuite_scripts//SLICER/Google_testsuite_scripts/scripts/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:139:5

SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).
```
--- end body ---

Memory leaks detected in the AP4_DescriptorFactory::CreateDescriptorFromStream function of Bento4 v1.6.0-641. The leak occurs when the function allocates memory for descriptors but fails to release it, potentially leading to increased memory usage and degradation of performance over time. This issue can be exploited in long-running applications that process multiple files, leading to resource exhaustion.